diff --git a/Makefile b/Makefile index 366ac67..02f742f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ XBE_TITLE=kernel\ test\ suite recursivewildcard=$(foreach d,$(wildcard $(1:=/*)),$(call recursivewildcard,$d,$2) $(filter $(subst *,%,$2),$d)) SRCS = $(call recursivewildcard,src,*.c) +SRCS := $(SRCS) $(call recursivewildcard,src,*.cpp) GIT_VERSION = "$(shell git describe --always --tags --first-parent --dirty)" NXDK_CFLAGS = -I$(CURDIR)/src -DGIT_VERSION=\"$(GIT_VERSION)\" +NXDK_CXXFLAGS = -I$(CURDIR)/src -DGIT_VERSION=\"$(GIT_VERSION)\" +NXDK_CXX = y include $(NXDK_DIR)/Makefile diff --git a/src/main.c b/src/main.cpp similarity index 74% rename from src/main.c rename to src/main.cpp index 1532611..55cd2a0 100644 --- a/src/main.c +++ b/src/main.cpp @@ -5,14 +5,16 @@ #include #include #include +#include +extern "C" { #include "util/hardware.h" #include "util/output.h" #include "util/misc.h" -#include "util/vector.h" #include "util/string_extra.h" #include "global.h" #include "include/api_tests.h" +} #ifndef GIT_VERSION #define GIT_VERSION "unknown" @@ -24,7 +26,7 @@ #define NEWLINE_DELIMITER "\r\n" // defined in util/output.h file, used privately here only -extern BOOL output_video; +extern "C" BOOL output_video; // Initialize the actual default values here if the config file is either successfully loaded before reading inputs or it failed to load. static void init_default_values() { @@ -77,7 +79,7 @@ void load_name_file(const char* file_path) if ((line = strtok_r(rest, NEWLINE_DELIMITER, &rest))) { size_t length = strlen(line); if (length) { - name_log = calloc(length + 1, sizeof(char)); + name_log = (char*)calloc(length + 1, sizeof(char)); strncpy(name_log, line, length); } } @@ -85,10 +87,10 @@ void load_name_file(const char* file_path) free(buffer); } -static vector tests_to_run; -static vector tests_exclude; +static std::bitset tests_to_run; +static std::bitset tests_to_exclude; -int load_conf_file(char *file_path) +int load_conf_file(const char *file_path) { print("Trying to open config file: %s", file_path); HANDLE handle = CreateFile( @@ -140,14 +142,20 @@ int load_conf_file(char *file_path) char *current_test; char *tests = strtok(NULL, NEWLINE_DELIMITER); while ((current_test = strtok_r(tests, ",", &tests))) { - vector_append(&tests_to_run, strtol(current_test, NULL, 16)); + unsigned long value = strtoul(current_test, NULL, 16); + if (value < kernel_api_tests_size) { + tests_to_run.set(value); + } } } 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)); + unsigned long value = strtoul(current_test, NULL, 16); + if (value < kernel_api_tests_size) { + tests_to_exclude.set(value); + } } } if (strcmp("disable-video", current_key) == 0) { @@ -156,7 +164,7 @@ int load_conf_file(char *file_path) if (strcmp("submitter", current_key) == 0) { char *value = strtok(NULL, NEWLINE_DELIMITER); size_t length = strlen(value); - submitter = calloc(length + 1, sizeof(char)); + submitter = (char*)calloc(length + 1, sizeof(char)); strncpy(submitter, value, length); } } @@ -165,57 +173,32 @@ 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_api_tests[test_n].func(test_n, kernel_api_tests[test_n].name); - } -} - static void run_tests() { print("Random seed used is %u", seed); - if (tests_to_run.size == 0) { - 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_api_tests_size > vector_get(&tests_exclude, i)) { - exclude_count++; - } - } - print("%d test(s) will be excluded.", exclude_count); - } - print("-------------------------------------------------------------"); - for (int k = 0; k < kernel_api_tests_size; k++) { - run_test(k); + if (tests_to_run.none()) { + print("No specific tests were requested. Running all tests."); + // Enable all tests. + tests_to_run.flip(); + if (tests_to_exclude.any()) { + // Exclude any tests requested. + tests_to_run &= ~tests_to_exclude; + print("%zu test(s) will be excluded.", tests_to_exclude.count()); } } else { 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); + if (tests_to_exclude.any()) { + const auto tests_to_run_excluded = tests_to_run & tests_to_exclude; + // Exclude any tests requested. + tests_to_run &= ~tests_to_run_excluded; + print("%zu test(s) will be excluded.", tests_to_run_excluded.count()); } - print("-----------------------------------------------------"); - for (int k = 0; k < tests_to_run.size; k++) { - run_test(vector_get(&tests_to_run, k)); + } + print("-------------------------------------------------------------"); + for (int i = 0; i < kernel_api_tests_size; i++) { + if (tests_to_run.test(i)) { + kernel_api_tests[i].func(i, kernel_api_tests[i].name); } } print("------------------------ End of Tests -----------------------"); @@ -223,15 +206,13 @@ static void run_tests() void main(void) { - vector_init(&tests_to_run, kernel_api_tests_size); - vector_init(&tests_exclude, 20); load_name_file("D:\\name.txt"); - char* output_file_name = "D:\\kernel_tests.log"; + char* output_file_name = (char*)"D:\\kernel_tests.log"; // If name_log buffer is allocated, then we know it does have actual input. if (name_log) { size_t name_log_length = strlen(name_log); name_log_length += strlen(name_log_format) - 2; // exclude %s - output_file_name = calloc(name_log_length + 1, sizeof(char)); + output_file_name = (char*)calloc(name_log_length + 1, sizeof(char)); snprintf(output_file_name, name_log_length, name_log_format, name_log); } if (!open_output_file(output_file_name)) { @@ -280,8 +261,6 @@ void main(void) print("PIC version: %s (%s)", pic_version, getConsoleType(pic_version)); run_tests(); - vector_free(&tests_to_run); - vector_free(&tests_exclude); close_output_file(); if (output_video) { diff --git a/src/util/output.c b/src/util/output.c index 6e8324e..7cd5c4a 100644 --- a/src/util/output.c +++ b/src/util/output.c @@ -13,7 +13,7 @@ BOOL output_video = FALSE; // NOTE: Must be set to a default of FALSE until conf static HANDLE output_filehandle = INVALID_HANDLE_VALUE; -void print(char* str, ...) +void print(const char* str, ...) { va_list args; enum { @@ -62,7 +62,7 @@ void print_test_footer( } } -BOOL open_output_file(char* file_path) +BOOL open_output_file(const char* file_path) { output_filehandle = CreateFile( file_path, diff --git a/src/util/output.h b/src/util/output.h index 861df86..91f58b9 100644 --- a/src/util/output.h +++ b/src/util/output.h @@ -2,7 +2,7 @@ #include -void print(char* str, ...); +void print(const char* str, ...); void print_test_header(int, const char*); void print_test_footer(int, const char*, BOOL); @@ -17,6 +17,6 @@ void print_test_footer(int, const char*, BOOL); // Real hardware can only display one screen of text at a time. Create an output // logfile to contain information for all tests. -BOOL open_output_file(char*); +BOOL open_output_file(const char*); int write_to_output_file(void*, DWORD); void close_output_file(); diff --git a/src/util/vector.c b/src/util/vector.c deleted file mode 100644 index d6190a1..0000000 --- a/src/util/vector.c +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include "vector.h" -#include "util/output.h" - -// 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, int capacity) -{ - vec->size = 0; - vec->capacity = capacity; - vec->data = malloc(sizeof(int) * vec->capacity); -} - -void vector_append(vector *vec, int value) -{ - vector_double_capacity_if_full(vec); - vec->data[vec->size++] = value; -} - -int vector_get(vector *vec, int index) -{ - if (index >= vec->size || index < 0) { - print("Error: vector index out of bound\n"); - Sleep(5000); - XReboot(); - } - return vec->data[index]; -} - -void vector_set(vector *vec, int index, int value) -{ - // zero fill the vector up to the desired index - while (index >= vec->size) { - vector_append(vec, 0); - } - vec->data[index] = value; -} - -void vector_double_capacity_if_full(vector *vec) -{ - if (vec->size >= vec->capacity) { - vec->capacity *= 2; - vec->data = realloc(vec->data, sizeof(int) * vec->capacity); - } -} - -void vector_free(vector *vec) -{ - if(vec!=NULL) - free(vec->data); -} diff --git a/src/util/vector.h b/src/util/vector.h deleted file mode 100644 index 3984120..0000000 --- a/src/util/vector.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -// This vector implementation is greatly inspired from a tutorial by hbs -// Ref: https://www.happybearsoftware.com/implementing-a-dynamic-array - -typedef struct { - int size; - int capacity; - int *data; -} vector; - -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); -void vector_double_capacity_if_full(vector *vec); -void vector_free(vector *vec);