Skip to content

Commit

Permalink
Merge pull request #105 from RadWolfie/use-std-bitset
Browse files Browse the repository at this point in the history
Replace custom vector to C++ std bitset class
  • Loading branch information
ergo720 authored Mar 15, 2024
2 parents bc69f87 + da8ee6d commit b4f297c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 133 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
95 changes: 37 additions & 58 deletions src/main.c → src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <bitset>

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"
Expand All @@ -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()
{
Expand Down Expand Up @@ -77,18 +79,18 @@ 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);
}
}

free(buffer);
}

static vector tests_to_run;
static vector tests_exclude;
static std::bitset<kernel_api_tests_size> tests_to_run;
static std::bitset<kernel_api_tests_size> 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(
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
}
Expand All @@ -165,73 +173,46 @@ 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 -----------------------");
}

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)) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/util/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/util/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <xboxkrnl/xboxdef.h>

void print(char* str, ...);
void print(const char* str, ...);
void print_test_header(int, const char*);
void print_test_footer(int, const char*, BOOL);

Expand All @@ -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();
54 changes: 0 additions & 54 deletions src/util/vector.c

This file was deleted.

17 changes: 0 additions & 17 deletions src/util/vector.h

This file was deleted.

0 comments on commit b4f297c

Please sign in to comment.