aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-06-15 14:57:21 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commitabe41cc2d5413faa8adeb16831f654435b6d0ef0 (patch)
tree3e08fe7d1857296ab9e41b5184b79005225361a5 /tests
parent829e0174acac0adee10595cc04dd32cb64753107 (diff)
Add compiler option for number of threads to use (instead of env)
Diffstat (limited to 'tests')
-rw-r--r--tests/main.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/main.c b/tests/main.c
index 3080807..c4c567d 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -120,13 +120,33 @@ static char* join_str(const char *str1, const char *str2, char delimiter) {
return buf;
}
+static CHECK_RESULT int get_thread_count_env_var(int *thread_count) {
+ char *threads;
+ threads = getenv("THREADS");
+ if(!threads)
+ return -1;
+ *thread_count = atoi(threads);
+ return 0;
+}
+
static void test_load(const char *filepath) {
amal_compiler compiler;
amal_compiler_options options;
char *full_path;
int result;
+ int num_threads;
+
+ result = get_thread_count_env_var(&num_threads);
+ if(result != 0)
+ num_threads = 0;
+
+ if(num_threads < 0) {
+ amal_log_error("Environment variable THREADS contains invalid number for threads. THREADS has to be at least 0 (0 = use the number of available threads on the system)");
+ exit(1);
+ }
amal_compiler_options_init(&options);
+ options.num_threads = num_threads;
++num_tests_run;
full_path = get_full_path(filepath);
/*
@@ -162,8 +182,19 @@ static void test_load_error(const char *filepath, const char *expected_error) {
amal_compiler compiler;
amal_compiler_options options;
int result;
+ int num_threads;
+
+ result = get_thread_count_env_var(&num_threads);
+ if(result != 0)
+ num_threads = 0;
+
+ if(num_threads < 0) {
+ amal_log_error("Environment variable THREADS contains invalid number for threads. THREADS has to be at least 0 (0 = use the number of available threads on the system)");
+ exit(1);
+ }
amal_compiler_options_init(&options);
+ options.num_threads = num_threads;
++num_tests_run;
options.error_callback = error_callback_assert;
ErrorExpectedData expected_data;
@@ -200,6 +231,7 @@ static void test_load_error(const char *filepath, const char *expected_error) {
free(expected_data.expected_error);
}
+
/* TODO: Restrict variables in global scope to const */
int main(int argc, char **argv) {
return_if_error(test_hash_map());