Skip to content

acl_profiler_test: use acl_test_setenv() and acl_test_unsetenv() #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 6 additions & 30 deletions test/acl_hal_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,8 @@ TEST(acl_hal, debugging) {
const char test_str[] = "hal debug printf test\n";
CHECK(acl_set_hal(&simple_hal));
const acl_hal_t *hal = acl_get_hal();
char env[] = "ACL_DEBUG=0";

#ifdef _WIN32
_putenv(env);
#else
putenv(env);
#endif
acl_test_setenv("ACL_DEBUG", "0");
char *acl_debug_env = getenv("ACL_DEBUG");
CHECK(acl_debug_env);
debug_mode = atoi(acl_debug_env);
Expand All @@ -318,32 +313,17 @@ TEST(acl_hal, debugging) {
CHECK_EQUAL(0, acl_print_debug_msg(""));

// Now start debugging.
env[10] = '4';
#ifdef _WIN32
_putenv(env);
#else
putenv(env);
#endif
acl_test_setenv("ACL_DEBUG", "4");
acl_debug_env = getenv("ACL_DEBUG");
CHECK(acl_debug_env);
debug_mode = atoi(acl_debug_env);
CHECK_EQUAL(4, debug_mode);
env[10] = '3';
#ifdef _WIN32
_putenv(env);
#else
putenv(env);
#endif
acl_test_setenv("ACL_DEBUG", "3");
acl_debug_env = getenv("ACL_DEBUG");
CHECK(acl_debug_env);
debug_mode = atoi(acl_debug_env);
CHECK_EQUAL(3, debug_mode);
env[10] = '2';
#ifdef _WIN32
_putenv(env);
#else
putenv(env);
#endif
acl_test_setenv("ACL_DEBUG", "2");
acl_debug_env = getenv("ACL_DEBUG");
CHECK(acl_debug_env);
debug_mode = atoi(acl_debug_env);
Expand All @@ -353,17 +333,13 @@ TEST(acl_hal, debugging) {
acl_print_debug_msg(test_str)); // -1 because source array includes a NUL
// char, but we don't print it.
CHECK_EQUAL(0, acl_print_debug_msg(""));
env[10] = '0';
#ifdef _WIN32
_putenv(env);
#else
putenv(env);
#endif
acl_test_setenv("ACL_DEBUG", "0");
acl_debug_env = getenv("ACL_DEBUG");
CHECK(acl_debug_env);
debug_mode = atoi(acl_debug_env);
CHECK_EQUAL(0, debug_mode);
CHECK_EQUAL(0, acl_print_debug_msg(test_str));
acl_test_unsetenv("ACL_DEBUG");

cl_int temp;
CHECK_EQUAL(1, hal->query_temperature(0, &temp));
Expand Down
69 changes: 14 additions & 55 deletions test/acl_profiler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,8 @@ MT_TEST_GROUP(acl_profile) {
enum { MAX_DEVICES = 100, m_num_devices_in_context = 3 };
void setup() {
if (threadNum() == 0) {
static char profile_runtime_env_var[] = "ACL_RUNTIME_PROFILING_ACTIVE=1";
static char profiler_timer_env_var[] = "ACL_PROFILE_TIMER=1";
#ifdef _WIN32
_putenv(profile_runtime_env_var);
_putenv(profiler_timer_env_var);
#else // Linux
putenv(profile_runtime_env_var);
putenv(profiler_timer_env_var);
#endif
acl_test_setenv("ACL_RUNTIME_PROFILING_ACTIVE", "1");
acl_test_setenv("ACL_PROFILE_TIMER", "1");
acl_test_setup_generic_system();
acl_dot_push(&m_devlog, &acl_platform.device_op_queue);

Expand All @@ -71,6 +64,8 @@ MT_TEST_GROUP(acl_profile) {
void teardown() {
syncThreads();
if (threadNum() == 0) {
acl_test_unsetenv("ACL_RUNTIME_PROFILING_ACTIVE");
acl_test_unsetenv("ACL_PROFILE_TIMER");
this->unload_program(m_program);
this->unload();
acl_test_teardown_generic_system();
Expand Down Expand Up @@ -449,63 +444,35 @@ TEST(acl_profile, valid_checks) {
}

TEST(acl_profile, shared_counter_checks) {
const std::string env_name = "ACL_INTERAL_SHARED_CONTROL_SETTING";
#ifdef _WIN32
_putenv((env_name + "=").c_str());
#else // Linux
unsetenv(env_name.c_str());
#endif
acl_test_unsetenv("ACL_INTERAL_SHARED_CONTROL_SETTING");
set_env_shared_counter_val();
CHECK_EQUAL(-1, get_env_profile_shared_counter_val());

for (int i = 0; i < 4; i++) {
const std::string env_value = std::to_string(i);
#ifdef _WIN32
_putenv((env_name + "=" + env_value).c_str());
#else // Linux
setenv(env_name.c_str(), env_value.c_str(), 1);
#endif
acl_test_setenv("ACL_INTERAL_SHARED_CONTROL_SETTING", env_value.c_str());
set_env_shared_counter_val();
CHECK_EQUAL(i, get_env_profile_shared_counter_val());
}

acl_test_unsetenv("ACL_INTERAL_SHARED_CONTROL_SETTING");
}

TEST(acl_profile, init_profiler) {
char profiling_runtime_invalid_value[] = "ACL_RUNTIME_PROFILING_ACTIVE=2";
char profiling_timer_invalid_value[] = "ACL_PROFILE_TIMER=2";
#ifdef _WIN32
_putenv(profiling_runtime_invalid_value);
_putenv(profiling_timer_invalid_value);
#else // Linux
putenv(profiling_runtime_invalid_value);
putenv(profiling_timer_invalid_value);
#endif
acl_test_setenv("ACL_RUNTIME_PROFILING_ACTIVE", "2");
acl_test_setenv("ACL_PROFILE_TIMER", "2");
ACL_LOCKED(acl_init_profiler());
CHECK(!is_profile_enabled());
CHECK(!is_profile_timer_on());

char profiling_runtime_enabled[] = "ACL_RUNTIME_PROFILING_ACTIVE=1";
char profiling_timer_enabled[] = "ACL_PROFILE_TIMER=1";
#ifdef _WIN32
_putenv(profiling_runtime_enabled);
_putenv(profiling_timer_enabled);
#else // Linux
putenv(profiling_runtime_enabled);
putenv(profiling_timer_enabled);
#endif
acl_test_setenv("ACL_RUNTIME_PROFILING_ACTIVE", "1");
acl_test_setenv("ACL_PROFILE_TIMER", "1");
ACL_LOCKED(acl_init_profiler());
CHECK(is_profile_enabled());
CHECK(is_profile_timer_on());

char profiling_runtime_disabled[] = "ACL_RUNTIME_PROFILING_ACTIVE=";
char profiling_timer_disabled[] = "ACL_PROFILE_TIMER=";
#ifdef _WIN32
_putenv(profiling_runtime_disabled);
_putenv(profiling_timer_disabled);
#else // Linux
putenv(profiling_runtime_disabled);
putenv(profiling_timer_disabled);
#endif
acl_test_unsetenv("ACL_RUNTIME_PROFILING_ACTIVE");
acl_test_unsetenv("ACL_PROFILE_TIMER");
ACL_LOCKED(acl_init_profiler());
CHECK(!is_profile_enabled());
CHECK(!is_profile_timer_on());
Expand Down Expand Up @@ -646,14 +613,6 @@ MT_TEST_GROUP(acl_no_profile) {
if (threadNum() == 0) {
remove(PROFILE_MON);

#ifdef _WIN32
char profile_runtime_env_var[] = "ACL_RUNTIME_PROFILING_ACTIVE=";
_putenv(profile_runtime_env_var);
#else // Linux
char profile_runtime_env_var[] = "ACL_RUNTIME_PROFILING_ACTIVE";
unsetenv(profile_runtime_env_var);
#endif

acl_test_setup_generic_system();

this->load();
Expand Down