[go: up one dir, main page]

Skip to content

Commit

Permalink
add method for resetting the global state
Browse files Browse the repository at this point in the history
Summary: Will only be used for testing. There is currently an issue when running the test sequentially under the same process - the static states are shared.

Reviewed By: NTillmann

Differential Revision: D26635120

fbshipit-source-id: 767d1f93bc8cbb3e99c809e11bb639d7e6b6dd55
  • Loading branch information
adicatana authored and facebook-github-bot committed Feb 26, 2021
1 parent 1e042ad commit e7b0ff4
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions libredex/ABExperimentContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ void ABExperimentContext::parse_experiments_states(
ABExperimentContextImpl::parse_experiments_states(states);
}

void ABExperimentContext::reset_global_state() {
ABExperimentContextImpl::reset_global_state();
}

void ABExperimentContext::force_test_mode() {
ABExperimentContextImpl::set_global_mode(ABGlobalMode::TEST);
}
Expand Down
3 changes: 3 additions & 0 deletions libredex/ABExperimentContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@ class ABExperimentContext {
* exists.
*/
static void force_control_mode();

private:
static void reset_global_state();
};
} // namespace ab_test
5 changes: 5 additions & 0 deletions libredex/ABExperimentContextImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,8 @@ void ABExperimentContextImpl::setup_context() {
m_cloned_cfg = std::make_unique<cfg::ControlFlowGraph>();
m_cfg->deep_copy(m_cloned_cfg.get());
}

void ABExperimentContextImpl::reset_global_state() {
s_experiments_states.clear();
INST_CNT = 0;
}
3 changes: 2 additions & 1 deletion libredex/ABExperimentContextImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class ABExperimentContextImpl : public ABExperimentContext {

bool use_test();
void setup_context();
static void reset_global_state();

friend class ABExperimentContext;
friend class ABExperimentContextTest;
friend struct ABExperimentContextTest;
};
} // namespace ab_test
4 changes: 4 additions & 0 deletions test/common/RedexTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ struct RedexTest : public testing::Test {

~RedexTest() { delete g_redex; }

void reset_ab_experiments_global_state() {
ab_test::ABExperimentContext::reset_global_state();
}

static void force_experiments_control_mode() {
ab_test::ABExperimentContext::force_control_mode();
}
Expand Down
5 changes: 3 additions & 2 deletions test/integ/ABExperimentContextTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

namespace ab_test {

class ABExperimentContextTest : public RedexIntegrationTest {
protected:
struct ABExperimentContextTest : public RedexIntegrationTest {
static void set_global_mode(ABGlobalMode mode) {
ABExperimentContextImpl::set_global_mode(mode);
}

void SetUp() override { reset_ab_experiments_global_state(); }
};

void change_called_method(DexMethod* m,
Expand Down
2 changes: 2 additions & 0 deletions test/integ/InstructionSequenceOutlinerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class InstructionSequenceOutlinerTest : public RedexIntegrationTest {
RedexIntegrationTest::run_passes(passes, nullptr, m_cfg);
}

void SetUp() override { reset_ab_experiments_global_state(); }

private:
Json::Value m_cfg;
};
Expand Down

0 comments on commit e7b0ff4

Please sign in to comment.