Skip to content

Commit

Permalink
lib+meta: Fix & clean up testrunner
Browse files Browse the repository at this point in the history
I knowingly broke it while hacking on the lib effort, but then promptly
forgot to fix it.
It is now fixed, and nicer to use. Just invoke via make:

make test -j6 suite=vecmath

suite is optional, omit it to run all tests in all suites.
  • Loading branch information
vkoskiv committed Jan 5, 2024
1 parent 238f075 commit cb6d8b3
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ output/*
.clangd
generated/*
.cache/*
tests/testrunner

# Heavy HDR files, just include a small one for demo
input/HDRs/*
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ $(BIN): $(OBJS) $(OBJDIR)
dummy:
@echo "Generating gitsha1.c"
$(shell sed "s/@GIT_SHA1@/`git rev-parse --verify HEAD || echo "NoHash" | cut -c 1-8`/g" src/common/gitsha1.c.in > generated/gitsha1.c)
# todo: Separate cleans out to sub-makefiles
clean:
rm -rf bin/* lib/* bindings/*o bindings/*.so

include cosmo.mk
include lib.mk
include tests/test.mk
40 changes: 0 additions & 40 deletions run-tests.sh

This file was deleted.

2 changes: 2 additions & 0 deletions src/common/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct intCoord {
int x, y;
};

static const struct vector g_world_up = { 0.0f, 1.0f, 0.0f };

//For defaults
static inline struct vector vec_zero() {
return (struct vector){ 0.0f, 0.0f, 0.0f };
Expand Down
10 changes: 4 additions & 6 deletions src/driver/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ bool parseDims(const char *dimStr, int *widthOut, int *heightOut) {
struct driver_args *args_parse(int argc, char **argv) {
struct driver_args *args = newConstantsDatabase();
static bool inputFileSet = false;
int testIdx = -1;
(void)testIdx;
char *alternatePath = NULL;
//Always omit the first argument.
for (int i = 1; i < argc; ++i) {
Expand Down Expand Up @@ -181,7 +179,7 @@ struct driver_args *args_parse(int argc, char **argv) {
if (testIdxStr) {
int n = atoi(testIdxStr);
n = n < 0 ? 0 : n;
testIdx = n;
setDatabaseInt(args, "test_idx", n);
}
}

Expand All @@ -191,18 +189,18 @@ struct driver_args *args_parse(int argc, char **argv) {
if (testIdxStr) {
int n = atoi(testIdxStr);
n = n < 0 ? 0 : n;
testIdx = n;
setDatabaseInt(args, "test_idx", n);
}
}

if (stringEquals(argv[i], "--tcount")) {
setDatabaseTag(args, "runTests");
testIdx = -2;
setDatabaseInt(args, "test_idx", -2);
}

if (stringEquals(argv[i], "--ptcount")) {
setDatabaseTag(args, "runTests");
testIdx = -3;
setDatabaseInt(args, "test_idx", -3);
}

if (stringEquals(argv[i], "--iterative")) {
Expand Down
37 changes: 37 additions & 0 deletions tests/runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

if [[ $# -eq 1 ]]; then
suite=$1
count=$(./tests/testrunner --suite "$suite" --tcount)
else
count=$(./tests/testrunner --tcount)
fi


echo "c-ray tiny test runner v0.3"
echo "Running $count tests."

failed_tests=0

i=0; while [ $i -le $((count - 1)) ]; do
if [[ -n "$suite" ]]; then
output=$(./tests/testrunner --suite "$suite" --test $i)
else
output=$(./tests/testrunner --test $i)
fi
if [[ $? -eq 0 ]]
then
echo "$output"
else
echo "$output"
failed_tests=$(( failed_tests + 1 ))
fi
i=$(( i + 1 ))
done
echo "Test suite finished. $((i - failed_tests))/$i tests passed."
if [[ $failed_tests -ne 0 ]]
then
exit 1
else
exit 0
fi
22 changes: 22 additions & 0 deletions tests/test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
BIN_test=tests/testrunner
OBJDIR_test=tests/obj
SRCS_test=$(shell find src/lib src/driver src/common generated/ tests/ -name '*.c' -not -name 'main.c')
TEST_HDRS=$(shell find tests/ -name '*.h')
OBJS_test=$(patsubst %.c, $(OBJDIR_test)/%.o, $(SRCS_test))
# suite=vector

test: $(BIN_test)
tests/runner.sh $(suite)

$(OBJDIR_test)/%.o: %.c $(TEST_HDRS) $(OBJDIR_test)
@mkdir -p '$(@D)'
@echo "CC $<"
@$(CC) $(CFLAGS) -DCRAY_TESTING -c $< -o $@
$(OBJDIR_test):
mkdir -p $@
$(BIN_test): $(OBJS_test) $(OBJDIR_test)
@echo "LD $@"
@$(CC) $(CFLAGS) $(OBJS_test) -o $@ $(LDFLAGS)

clean_test:
rm -rf tests/obj tests/testrunner
2 changes: 1 addition & 1 deletion tests/test_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "../src/common/color.h"
#include "../src/common/vendored/cJSON.h"
#include "../src/driver/json_loader.h"
#include "../src/common/json_loader.h"
#include "../src/common/node_parse.h"

bool parser_color_rgb(void) {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "../src/lib/protocol/protocol.h"
#include "../src/common/fileio.h"
#include "../src/common/vendored/cJSON.h"
#include "../src/driver/json_loader.h"
#include "../src/common/json_loader.h"
#include "../src/common/string.h"

void silence_stdout(int *bak, int *new) {
Expand Down
2 changes: 0 additions & 2 deletions tests/test_thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ void test_task(void *arg) {

*input += 1000;

printf("tid=%lu, input=%d, val=%d\n", pthread_self(), old, *input);
if (*input % 2) {
timer_sleep_ms(10);
}
Expand All @@ -33,7 +32,6 @@ bool test_thread_pool(void) {
int *values = calloc(iterations, sizeof(*values));
for (int i = 0; i < iterations; ++i) {
values[i] = i;
printf("values[i] = %i\n", i);
thread_pool_enqueue(pool, test_task, values + i);
}

Expand Down
28 changes: 7 additions & 21 deletions tests/testrunner.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
//
// testrunner.c
// C-ray
// c-ray
//
// Created by Valtteri on 23.6.2020.
// Copyright © 2020-2021 Valtteri Koskivuori. All rights reserved.
// Copyright © 2020-2024 Valtteri Koskivuori. All rights reserved.
//

#include "../src/includes.h"
#include "../src/common/logging.h"
#include "../src/common/timer.h"
#include "../src/driver/args.h"

#include "../src/common/assert.h"
#include "testrunner.h"

#ifdef CRAY_TESTING

int firstTestIdx(char *suite);
int firstPerfTestIdx(char *suite);

Expand Down Expand Up @@ -151,16 +150,12 @@ int getPerfTestCount(char *suite) {
return perf_test_count;
}

#if defined(CR_BUILDING_LIB)

// FIXME: This doesn't even get built, fix
int main(int argc, char *argv[]) {
struct driver_args *args = args_parse(argc, argv);
if (args_is_set(args, "runTests") || args_is_set(args, "runPerfTests")) {
#if defined(CRAY_TESTING)
char *suite = NULL;
if (args_is_set(args, "test_suite")) suite = getDatabaseString(args, "test_suite");
switch (testIdx) {
char *suite = args_string(args, "test_suite");
int test_idx = args_int(args, "test_idx");
switch (test_idx) {
case -3:
printf("%i", getPerfTestCount(suite));
exit(0);
Expand All @@ -173,18 +168,9 @@ int main(int argc, char *argv[]) {
exit(args_is_set(args, "runPerfTests") ? runPerfTests(suite) : runTests(suite));
break;
default:
exit(args_is_set(args, "runPerfTests") ? runPerfTest(testIdx, suite) : runTest(testIdx, suite));
exit(args_is_set(args, "runPerfTests") ? runPerfTest(test_idx, suite) : runTest(test_idx, suite));
break;
}
#else
logr(warning, "You need to compile with tests enabled.\n");
logr(warning, "Run: `cmake . -DTESTING=True` and then `make`\n");
exit(-1);
#endif
}
return 0;
}

#endif

#endif
10 changes: 3 additions & 7 deletions tests/testrunner.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
//
// testrunner.h
// C-ray
// c-ray
//
// Created by Valtteri on 23.6.2020.
// Copyright © 2020-2021 Valtteri Koskivuori. All rights reserved.
// Copyright © 2020-2024 Valtteri Koskivuori. All rights reserved.
//

#pragma once

/*
C-ray integrated testing system.
*/
// c-ray integrated testing system.

#ifdef CRAY_TESTING
int runTests(char *suite);
int runPerfTests(char *suite);
int runTest(unsigned test, char *suite);
int runPerfTest(unsigned test, char *suite);
int getTestCount(char *suite);
int getPerfTestCount(char *suite);
#endif

0 comments on commit cb6d8b3

Please sign in to comment.