From e465b41c3a022c5edff1fd22178de0dba8635e71 Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Fri, 9 Feb 2024 18:11:04 +0000 Subject: [PATCH] add tests-exclude option --- src/include/func_table.h | 2 ++ src/main.c | 59 +++++++++++++++++++++++++++++++++++----- src/util/vector.c | 4 +-- src/util/vector.h | 2 +- 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/include/func_table.h b/src/include/func_table.h index bab11c5..3b2c6d2 100644 --- a/src/include/func_table.h +++ b/src/include/func_table.h @@ -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); diff --git a/src/main.c b/src/main.c index 299ba40..c2414ff 100644 --- a/src/main.c +++ b/src/main.c @@ -35,6 +35,7 @@ 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) { @@ -90,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); } @@ -105,22 +113,57 @@ 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 remainder_size = 0; + for (int i = 0; i < tests_exclude.size; i++) { + if (kernel_thunk_table_size > vector_get(&tests_exclude, i)) { + remainder_size++; + } + } + print("%d test(s) will be exclude.", remainder_size); + } 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 remainder_size = 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)) { + remainder_size++; + break; + } + } + } + print("%d test(s) will be exclude.", remainder_size); + } print("-----------------------------------------------------"); for (int k = 0; k < tests_to_run.size; k++) { - kernel_thunk_table[vector_get(&tests_to_run, k)](); + run_test(vector_get(&tests_to_run, k)); } } print("------------------------ End of Tests -----------------------"); @@ -128,7 +171,8 @@ static void run_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; } @@ -169,6 +213,7 @@ void main(void) run_tests(); vector_free(&tests_to_run); + vector_free(&tests_exclude); close_output_file(); if (output_video) { diff --git a/src/util/vector.c b/src/util/vector.c index 7e57849..d6190a1 100644 --- a/src/util/vector.c +++ b/src/util/vector.c @@ -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); } diff --git a/src/util/vector.h b/src/util/vector.h index 68898cf..3984120 100644 --- a/src/util/vector.h +++ b/src/util/vector.h @@ -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);