Camera2: Tests -- Fork each test before executing it
Use CAMERA2_TEST_FORKING_DISABLED=1 environment variable to override this
behavior (e.g. when wanting to attach gdb to the test app).
Change-Id: Ib639885bdb827fc2415c878cbcb1b2d84dff687b
diff --git a/tests/camera2/main.cpp b/tests/camera2/main.cpp
index 40b9872..92c117a 100644
--- a/tests/camera2/main.cpp
+++ b/tests/camera2/main.cpp
@@ -14,12 +14,33 @@
* limitations under the License.
*/
+#include <stdlib.h>
+
#include <gtest/gtest.h>
+#include "TestForkerEventListener.h"
+
+using android::camera2::tests::TestForkerEventListener;
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
+ {
+ //TODO: have a command line flag as well
+ char *env = getenv("CAMERA2_TEST_FORKING_DISABLED");
+ if (env) {
+ int forking = atoi(env);
+
+ TestForkerEventListener::SetForking(!forking);
+ }
+ }
+
+ // Gets hold of the event listener list.
+ ::testing::TestEventListeners& listeners =
+ ::testing::UnitTest::GetInstance()->listeners();
+ // Adds a listener to the end. Google Test takes the ownership.
+ listeners.Append(new TestForkerEventListener());
+
int ret = RUN_ALL_TESTS();
return ret;