summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJinkun Jang <jinkun.jang@samsung.com>2013-03-13 01:51:48 +0900
committerJinkun Jang <jinkun.jang@samsung.com>2013-03-13 01:51:48 +0900
commitd6aa47559c38d7e20d6d6a7a3671fa48ed58b9eb (patch)
tree5fbc758662a7866e32ec1adcfd9149c71987549e /test
parent8fe192a924f295972402d46141e39b86241a1441 (diff)
downloadoma-ds-agent-d6aa47559c38d7e20d6d6a7a3671fa48ed58b9eb.tar.gz
oma-ds-agent-d6aa47559c38d7e20d6d6a7a3671fa48ed58b9eb.tar.bz2
oma-ds-agent-d6aa47559c38d7e20d6d6a7a3671fa48ed58b9eb.zip
Tizen 2.1 base
Diffstat (limited to 'test')
-rwxr-xr-xtest/include/suites/unit_test_sample_suite.h25
-rwxr-xr-xtest/include/unit_test_common.h26
-rwxr-xr-xtest/include/unit_test_run.h32
-rwxr-xr-xtest/include/unit_test_suites.h30
-rwxr-xr-xtest/src/oma_test_main.c24
-rwxr-xr-xtest/src/suites/unit_test_sample_suite.c63
-rwxr-xr-xtest/src/unit_test_run.c131
7 files changed, 331 insertions, 0 deletions
diff --git a/test/include/suites/unit_test_sample_suite.h b/test/include/suites/unit_test_sample_suite.h
new file mode 100755
index 0000000..1f4d857
--- /dev/null
+++ b/test/include/suites/unit_test_sample_suite.h
@@ -0,0 +1,25 @@
+/*
+ * oma-ds-agent
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef UNIT_TEST_SUITE_H_
+#define UNIT_TEST_SUITE_H_
+
+#include "unit_test_common.h"
+
+Suite *sample_suite(void);
+
+#endif /* UNIT_TEST_SUITE_H_ */
diff --git a/test/include/unit_test_common.h b/test/include/unit_test_common.h
new file mode 100755
index 0000000..6ac25f2
--- /dev/null
+++ b/test/include/unit_test_common.h
@@ -0,0 +1,26 @@
+/*
+ * oma-ds-agent
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef UNIT_TEST_COMMON_H_
+#define UNIT_TEST_COMMON_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <check.h>
+
+#endif /* UNIT_TEST_COMMON_H_ */
diff --git a/test/include/unit_test_run.h b/test/include/unit_test_run.h
new file mode 100755
index 0000000..3f22e23
--- /dev/null
+++ b/test/include/unit_test_run.h
@@ -0,0 +1,32 @@
+/*
+ * oma-ds-agent
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef UNIT_TEST_H_
+#define UNIT_TEST_H_
+
+#include "unit_test_common.h"
+
+typedef enum run_unit_test_mode run_unit_test_mode_t;
+enum run_unit_test_mode {
+ FUNCTION_MODE, /* unit test runs just like function */
+ /* good for debugging */
+ FORK_MODE
+};
+
+int unit_test_run(run_unit_test_mode_t mode);
+
+#endif /* UNIT_TEST_H_ */
diff --git a/test/include/unit_test_suites.h b/test/include/unit_test_suites.h
new file mode 100755
index 0000000..1897534
--- /dev/null
+++ b/test/include/unit_test_suites.h
@@ -0,0 +1,30 @@
+/*
+ * oma-ds-agent
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef UNIT_TEST_SUITES_H_
+#define UNIT_TEST_SUITES_H_
+
+#include "unit_test_common.h"
+#include "suites/unit_test_sample_suite.h"
+
+/* define here suites to be tested */
+typedef Suite *(*SUITE_FUNCTION) (void);
+static SUITE_FUNCTION suiteFunctions[] = {
+ sample_suite
+};
+
+#endif /* UNIT_TEST_SUITES_H_ */
diff --git a/test/src/oma_test_main.c b/test/src/oma_test_main.c
new file mode 100755
index 0000000..894cc37
--- /dev/null
+++ b/test/src/oma_test_main.c
@@ -0,0 +1,24 @@
+/*
+ * oma-ds-agent
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "unit_test_run.h"
+
+int main(void)
+{
+ int test_success = unit_test_run(FUNCTION_MODE);
+ return test_success;
+}
diff --git a/test/src/suites/unit_test_sample_suite.c b/test/src/suites/unit_test_sample_suite.c
new file mode 100755
index 0000000..348241e
--- /dev/null
+++ b/test/src/suites/unit_test_sample_suite.c
@@ -0,0 +1,63 @@
+/*
+ * oma-ds-agent
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "unit_test_common.h"
+#include "suites/unit_test_sample_suite.h"
+
+START_TEST(sample_test1)
+{
+ fail_unless(2 != 1, "2 != 1 failed");
+ fail_unless(3 != 1, "3 != 1 failed");
+}
+
+END_TEST START_TEST(sample_test2)
+{
+ /* unit test code */
+ fail_unless(10 != 5, "10 != 5 failed");
+}
+
+END_TEST Suite *sample_suite(void)
+{
+ /* create test suite */
+ Suite *s = suite_create("Sample");
+
+ /* test case create and add in suite */
+ {
+ TCase *tcase = tcase_create("SampleTestCase");
+ /* TODO : explain following lines */
+ /* tcase_add_unchecked_fixture (tcase, setup, teardown); */
+ /* tcase_add_checked_fixture (tcase, setup, teardown); */
+
+ tcase_add_test(tcase, sample_test1);
+ tcase_add_test(tcase, sample_test2);
+ /* TODO : explain following lines */
+ tcase_set_timeout(tcase, 1);
+
+ suite_add_tcase(s, tcase);
+ }
+
+ /* create another test case and add to test suite just like above code */
+ {
+ TCase *tc_core2 = tcase_create("Sample2");
+ tcase_add_test(tc_core2, sample_test1);
+ tcase_add_test(tc_core2, sample_test2);
+ tcase_set_timeout(tc_core2, 1);
+ suite_add_tcase(s, tc_core2);
+ }
+
+ return s;
+}
diff --git a/test/src/unit_test_run.c b/test/src/unit_test_run.c
new file mode 100755
index 0000000..6a07e4c
--- /dev/null
+++ b/test/src/unit_test_run.c
@@ -0,0 +1,131 @@
+/*
+ * oma-ds-agent
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "unit_test_common.h"
+#include "unit_test_run.h"
+#include "unit_test_suites.h"
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+/* introduction to unit test using check by yangsuh
+ * SRunner : runner of all test which belong to added suites
+ * Suite : container of test cases(TCase)
+ * TCase : container of tests
+ * test : container of many asserts
+ *
+ * SRunner has fork_status option. I will set this option to CK_FORK which means
+ * not stopping until all test finished.
+ * (Of course, when error like SIGSEGV occurs or test failed, current test will be stopped
+ * and goes to next test)
+ */
+
+typedef enum fork_status fork_status_t;
+int unit_test_main(fork_status_t fork_status)
+{
+ SRunner *sr = NULL;
+
+ /* srunner build up by defined test suites */
+ int suite_count = sizeof(suiteFunctions) / sizeof(SUITE_FUNCTION);
+ fprintf(stderr, "total test suites number = %d\n", suite_count);
+
+ if (suite_count == 0) {
+ return 0; /* nothing to do */
+ } else { /* suite_count > 0 */
+ SUITE_FUNCTION suite_func = NULL;
+
+ int i = 0;
+ for (i = 0; i < suite_count; i++) {
+ suite_func = suiteFunctions[i];
+ Suite *s = suite_func();
+ if (s != NULL) {
+ if (i == 0) {
+ sr = srunner_create(s);
+ } else if (i > 0 && i < suite_count) {
+ srunner_add_suite(sr, s);
+ }
+ } else {
+ fprintf(stderr, "%s\n", "invalid suite function");
+ }
+ }
+ }
+
+ /* srunner setting */
+ srunner_set_log(sr, "/tmp/test.log"); /* set log file */
+ srunner_set_fork_status(sr, fork_status); /* set fork status of Runner */
+
+ srunner_run_all(sr, CK_VERBOSE); /* set print mode to verbose */
+ srunner_free(sr);
+
+ return 0;
+}
+
+/* TODO : return handling */
+static inline int unit_test_run_fork_mode()
+{
+ pid_t pid_w;
+ pid_t pid;
+ int status = 0;
+
+ pid = fork();
+ if (pid == -1)
+ fprintf(stderr, "%s\n", "Error in call to fork");
+ if (pid == 0) {
+ /* child process : run unit_test_main */
+ unit_test_main(CK_FORK);
+ exit(EXIT_SUCCESS);
+ } else {
+ /* parent process */
+ fprintf(stderr, "test process pid = %d", pid);
+ pid_w = waitpid(pid, &status, 0);
+
+ if (pid_w == pid) {
+ fprintf(stderr, "%s\n", "test finished successfully");
+ return 1; /* test finished */
+ } else {
+ fprintf(stderr, "%s\n", "test failed");
+ return 0; /* test error */
+ }
+ }
+
+ return status;
+}
+
+/* running as main function will be need during debugging */
+/* TODO : return handling */
+static inline int unit_test_run_function_mode()
+{
+ return unit_test_main(CK_NOFORK);
+}
+
+int unit_test_run(run_unit_test_mode_t mode)
+{
+ int success = 1; /* success */
+
+ switch (mode) {
+ case FORK_MODE:
+ success = unit_test_run_fork_mode();
+ break;
+ case FUNCTION_MODE:
+ success = unit_test_run_function_mode();
+ break;
+ default:
+ break;
+ }
+
+ return success;
+}