From abe41cc2d5413faa8adeb16831f654435b6d0ef0 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 15 Jun 2019 14:57:21 +0200 Subject: Add compiler option for number of threads to use (instead of env) --- tests/main.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests') 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()); -- cgit v1.2.3