Skip to content

Commit

Permalink
Merge pull request #96 from RadWolfie/exclude-tests
Browse files Browse the repository at this point in the history
Add exclude tests option
  • Loading branch information
RadWolfie authored Feb 19, 2024
2 parents 74268f1 + ec31883 commit 7abd612
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 17 deletions.
3 changes: 0 additions & 3 deletions src/global.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#include "util/vector.h"

const char* failed_text = "FAILED";
const char* passed_text = "PASSED";

unsigned int seed = 0;
vector tests_to_run;
3 changes: 0 additions & 3 deletions src/global.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#pragma once

#include "util/vector.h"

#define NV2A_MMIO_BASE 0xFD000000

extern const char* failed_text;
extern const char* passed_text;

extern unsigned int seed;
extern vector tests_to_run;
2 changes: 2 additions & 0 deletions src/include/func_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,5 @@ void (*kernel_thunk_table[])(void) =
test_MmDbgReleaseAddress, // 0x017A (377) DEVKIT
test_MmDbgWriteCheck, // 0x017A (378) DEVKIT
};

static const int kernel_thunk_table_size = ARRAY_SIZE(kernel_thunk_table);
63 changes: 55 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ static void init_default_values()

static char *submitter = NULL;

static vector tests_to_run;
static vector tests_exclude;

int load_conf_file(char *file_path)
{
print("Trying to open config file: %s", file_path);
Expand Down Expand Up @@ -88,6 +91,13 @@ int load_conf_file(char *file_path)
vector_append(&tests_to_run, strtol(current_test, NULL, 16));
}
}
if (strcmp("tests-exclude", current_key) == 0) {
char *current_test;
char *tests = strtok(NULL, NEWLINE_DELIMITER);
while ((current_test = strtok_r(tests, ",", &tests))) {
vector_append(&tests_exclude, strtol(current_test, NULL, 16));
}
}
if (strcmp("disable-video", current_key) == 0) {
output_video = !strtoul(strtok(NULL, NEWLINE_DELIMITER), NULL, 16);
}
Expand All @@ -103,30 +113,66 @@ int load_conf_file(char *file_path)
return 0;
}

static void run_test(int test_n) {
for (int i = 0; i < tests_exclude.size; i++) {
// If a match is found in the exclusion list, then we skip the test.
if (test_n == vector_get(&tests_exclude, i)) {
test_n = -1;
break;
}
}
// Skip the test if test_n is a negative number.
if (test_n >= 0) {
kernel_thunk_table[test_n]();
}
}

static void run_tests()
{
print("Random seed used is %u", seed);
if (tests_to_run.size == 0) {
print("No Specific tests specified. Running all tests (Single Pass).");
print("No specific tests were requested. Running all tests (Single Pass).");
if (tests_exclude.size) {
int exclude_count = 0;
for (int i = 0; i < tests_exclude.size; i++) {
if (kernel_thunk_table_size > vector_get(&tests_exclude, i)) {
exclude_count++;
}
}
print("%d test(s) will be excluded.", exclude_count);
}
print("-------------------------------------------------------------");
int table_size = ARRAY_SIZE(kernel_thunk_table);
for (int k=0; k<table_size; k++) {
kernel_thunk_table[k]();
for (int k = 0; k < kernel_thunk_table_size; k++) {
run_test(k);
}
}
else {
print("Config File Was Loaded. Only running requested tests.");
print("A config file was loaded. Only running requested tests.");
if (tests_exclude.size) {
int exclude_count = 0;
for (int k = 0; k < tests_to_run.size; k++) {
int test_n = vector_get(&tests_to_run, k);
for (int i = 0; i < tests_exclude.size; i++) {
if (test_n == vector_get(&tests_exclude, i)) {
exclude_count++;
break;
}
}
}
print("%d test(s) will be excluded.", exclude_count);
}
print("-----------------------------------------------------");
for (int k=0; k<tests_to_run.size; k++) {
kernel_thunk_table[vector_get(&tests_to_run, k)]();
for (int k = 0; k < tests_to_run.size; k++) {
run_test(vector_get(&tests_to_run, k));
}
}
print("------------------------ End of Tests -----------------------");
}

void main(void)
{
vector_init(&tests_to_run);
vector_init(&tests_to_run, kernel_thunk_table_size);
vector_init(&tests_exclude, 20);
if (!open_output_file("D:\\kernel_tests.log")) {
return;
}
Expand Down Expand Up @@ -167,6 +213,7 @@ void main(void)
run_tests();

vector_free(&tests_to_run);
vector_free(&tests_exclude);
close_output_file();

if (output_video) {
Expand Down
4 changes: 2 additions & 2 deletions src/util/vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// This vector implementation is greatly inspired from a tutorial by hbs
// Ref: https://www.happybearsoftware.com/implementing-a-dynamic-array

void vector_init(vector *vec)
void vector_init(vector *vec, int capacity)
{
vec->size = 0;
vec->capacity = 379;
vec->capacity = capacity;
vec->data = malloc(sizeof(int) * vec->capacity);
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ typedef struct {
int *data;
} vector;

void vector_init(vector *vec);
void vector_init(vector *vec, int capacity);
void vector_append(vector *vec, int value);
int vector_get(vector *vec, int index);
void vector_set(vector *vec, int index, int value);
Expand Down

0 comments on commit 7abd612

Please sign in to comment.