Skip to content

Commit c5a738b

Browse files
committed
acl_profiler_test: use acl_test_setenv() and acl_test_unsetenv()
Ensure each setenv() is matched with unsetenv(). This amends #196 Signed-off-by: Peter Colberg <[email protected]>
1 parent 91fcfd3 commit c5a738b

File tree

1 file changed

+14
-55
lines changed

1 file changed

+14
-55
lines changed

test/acl_profiler_test.cpp

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,8 @@ MT_TEST_GROUP(acl_profile) {
5050
enum { MAX_DEVICES = 100, m_num_devices_in_context = 3 };
5151
void setup() {
5252
if (threadNum() == 0) {
53-
static char profile_runtime_env_var[] = "ACL_RUNTIME_PROFILING_ACTIVE=1";
54-
static char profiler_timer_env_var[] = "ACL_PROFILE_TIMER=1";
55-
#ifdef _WIN32
56-
_putenv(profile_runtime_env_var);
57-
_putenv(profiler_timer_env_var);
58-
#else // Linux
59-
putenv(profile_runtime_env_var);
60-
putenv(profiler_timer_env_var);
61-
#endif
53+
acl_test_setenv("ACL_RUNTIME_PROFILING_ACTIVE", "1");
54+
acl_test_setenv("ACL_PROFILE_TIMER", "1");
6255
acl_test_setup_generic_system();
6356
acl_dot_push(&m_devlog, &acl_platform.device_op_queue);
6457

@@ -71,6 +64,8 @@ MT_TEST_GROUP(acl_profile) {
7164
void teardown() {
7265
syncThreads();
7366
if (threadNum() == 0) {
67+
acl_test_unsetenv("ACL_RUNTIME_PROFILING_ACTIVE");
68+
acl_test_unsetenv("ACL_PROFILE_TIMER");
7469
this->unload_program(m_program);
7570
this->unload();
7671
acl_test_teardown_generic_system();
@@ -449,63 +444,35 @@ TEST(acl_profile, valid_checks) {
449444
}
450445

451446
TEST(acl_profile, shared_counter_checks) {
452-
const std::string env_name = "ACL_INTERAL_SHARED_CONTROL_SETTING";
453-
#ifdef _WIN32
454-
_putenv((env_name + "=").c_str());
455-
#else // Linux
456-
unsetenv(env_name.c_str());
457-
#endif
447+
acl_test_unsetenv("ACL_INTERAL_SHARED_CONTROL_SETTING");
458448
set_env_shared_counter_val();
459449
CHECK_EQUAL(-1, get_env_profile_shared_counter_val());
460450

461451
for (int i = 0; i < 4; i++) {
462452
const std::string env_value = std::to_string(i);
463-
#ifdef _WIN32
464-
_putenv((env_name + "=" + env_value).c_str());
465-
#else // Linux
466-
setenv(env_name.c_str(), env_value.c_str(), 1);
467-
#endif
453+
acl_test_setenv("ACL_INTERAL_SHARED_CONTROL_SETTING", env_value.c_str());
468454
set_env_shared_counter_val();
469455
CHECK_EQUAL(i, get_env_profile_shared_counter_val());
470456
}
457+
458+
acl_test_unsetenv("ACL_INTERAL_SHARED_CONTROL_SETTING");
471459
}
472460

473461
TEST(acl_profile, init_profiler) {
474-
char profiling_runtime_invalid_value[] = "ACL_RUNTIME_PROFILING_ACTIVE=2";
475-
char profiling_timer_invalid_value[] = "ACL_PROFILE_TIMER=2";
476-
#ifdef _WIN32
477-
_putenv(profiling_runtime_invalid_value);
478-
_putenv(profiling_timer_invalid_value);
479-
#else // Linux
480-
putenv(profiling_runtime_invalid_value);
481-
putenv(profiling_timer_invalid_value);
482-
#endif
462+
acl_test_setenv("ACL_RUNTIME_PROFILING_ACTIVE", "2");
463+
acl_test_setenv("ACL_PROFILE_TIMER", "2");
483464
ACL_LOCKED(acl_init_profiler());
484465
CHECK(!is_profile_enabled());
485466
CHECK(!is_profile_timer_on());
486467

487-
char profiling_runtime_enabled[] = "ACL_RUNTIME_PROFILING_ACTIVE=1";
488-
char profiling_timer_enabled[] = "ACL_PROFILE_TIMER=1";
489-
#ifdef _WIN32
490-
_putenv(profiling_runtime_enabled);
491-
_putenv(profiling_timer_enabled);
492-
#else // Linux
493-
putenv(profiling_runtime_enabled);
494-
putenv(profiling_timer_enabled);
495-
#endif
468+
acl_test_setenv("ACL_RUNTIME_PROFILING_ACTIVE", "1");
469+
acl_test_setenv("ACL_PROFILE_TIMER", "1");
496470
ACL_LOCKED(acl_init_profiler());
497471
CHECK(is_profile_enabled());
498472
CHECK(is_profile_timer_on());
499473

500-
char profiling_runtime_disabled[] = "ACL_RUNTIME_PROFILING_ACTIVE=";
501-
char profiling_timer_disabled[] = "ACL_PROFILE_TIMER=";
502-
#ifdef _WIN32
503-
_putenv(profiling_runtime_disabled);
504-
_putenv(profiling_timer_disabled);
505-
#else // Linux
506-
putenv(profiling_runtime_disabled);
507-
putenv(profiling_timer_disabled);
508-
#endif
474+
acl_test_unsetenv("ACL_RUNTIME_PROFILING_ACTIVE");
475+
acl_test_unsetenv("ACL_PROFILE_TIMER");
509476
ACL_LOCKED(acl_init_profiler());
510477
CHECK(!is_profile_enabled());
511478
CHECK(!is_profile_timer_on());
@@ -646,14 +613,6 @@ MT_TEST_GROUP(acl_no_profile) {
646613
if (threadNum() == 0) {
647614
remove(PROFILE_MON);
648615

649-
#ifdef _WIN32
650-
char profile_runtime_env_var[] = "ACL_RUNTIME_PROFILING_ACTIVE=";
651-
_putenv(profile_runtime_env_var);
652-
#else // Linux
653-
char profile_runtime_env_var[] = "ACL_RUNTIME_PROFILING_ACTIVE";
654-
unsetenv(profile_runtime_env_var);
655-
#endif
656-
657616
acl_test_setup_generic_system();
658617

659618
this->load();

0 commit comments

Comments
 (0)