Skip to content

Commit

Permalink
acl_profiler_test: use acl_test_setenv() and acl_test_unsetenv()
Browse files Browse the repository at this point in the history
Ensure each setenv() is matched with unsetenv().

This amends intel#196

Signed-off-by: Peter Colberg <peter.colberg@intel.com>
  • Loading branch information
pcolberg committed Nov 8, 2022
1 parent 91fcfd3 commit 2bda6bc
Showing 1 changed file with 14 additions and 55 deletions.
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

0 comments on commit 2bda6bc

Please # to comment.