Add DB::Transaction class. Change tests to use new libprivilege API.
authorMarcin Lis <m.lis@samsung.com>
Tue, 24 Sep 2013 10:49:23 +0000 (12:49 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 23 Jan 2014 14:19:09 +0000 (15:19 +0100)
[Issue#]       SSDWSSP-183
[Bug/Feature]  N/A
[Cause]        N/A
[Solution]     Added class DB::Transaction which opens and closes transaction.
               Added macros DB_BEGIN and DB_END that determine DB::Transaction
               class object lifetime which in turn start and commit
               db transactions.
               Also macros used in tests to reduce test-execution time.
[Verification] Build, install, run tests.

Change-Id: I90b48c27e352fb24e9c57ec7b1bb9005d8f0fd2d

tests/common/tests_common.cpp
tests/common/tests_common.h
tests/libprivilege-control-tests/test_cases.cpp
tests/libprivilege-control-tests/test_cases_nosmack.cpp
tests/libprivilege-control-tests/test_cases_stress.cpp

index 34e7da5..7f974b0 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "tests_common.h"
 
+int DB::Transaction::db_result = PC_OPERATION_SUCCESS;
+
 int smack_runtime_check(void)
 {
     static int smack_present = -1;
index 4f753fc..77a63fa 100644 (file)
@@ -28,6 +28,7 @@
 #include <dpl/test/test_runner.h>
 #include <dpl/test/test_runner_child.h>
 #include <dpl/test/test_runner_multiprocess.h>
+#include <privilege-control.h>
 
 int smack_runtime_check(void);
 int smack_check(void);
@@ -116,5 +117,38 @@ int smack_check(void);
     }                                                                                \
     void Proc##Multi()
 
+namespace DB {
+
+    class Transaction
+    {
+    public:
+
+        static int db_result;
+
+        Transaction() {
+            db_result = perm_begin();
+            RUNNER_ASSERT_MSG(PC_OPERATION_SUCCESS == db_result,
+                              "perm_begin returned: " << db_result);
+        }
+
+        ~Transaction() {
+            db_result = perm_end();
+        }
+    };
+} // namespace DB
+
+// Database Transaction macros
+// PLEASE NOTE Both DB_BEGIN and DB_END need to be called in the same scope.
+// They are used to prevent developer from forgetting to close transaction.
+// Also note that variables defined between these macros will not be visible
+// after DB_END.
+#define DB_BEGIN                       \
+        {                              \
+        DB::Transaction db_transaction;
+
+#define DB_END }                                                                   \
+        RUNNER_ASSERT_MSG(PC_OPERATION_SUCCESS == DB::Transaction::db_result,      \
+        "perm_end returned: " << DB::Transaction::db_result);
+
 
 #endif
index 0781d11..8894234 100644 (file)
@@ -313,6 +313,9 @@ RUNNER_TEST(privilege_control02_app_label_dir)
 RUNNER_TEST_SMACK(privilege_control03_app_label_shared_dir)
 {
     int result;
+
+    DB_BEGIN
+
     result = perm_app_install(APP_ID);
     RUNNER_ASSERT_MSG(result == 0, "perm_app_install returned " << result << ". Errno: " << strerror(errno));
 
@@ -328,6 +331,8 @@ RUNNER_TEST_SMACK(privilege_control03_app_label_shared_dir)
     result = perm_app_setup_path(APP_ID, TEST_APP_DIR, APP_PATH_GROUP_RW, APPID_SHARED_DIR);
     RUNNER_ASSERT_MSG(result == 0, "perm_app_setup_path() failed");
 
+    DB_END
+
     result = nftw(TEST_APP_DIR, &nftw_check_labels_app_shared_dir, FTW_MAX_FDS, FTW_PHYS);
     RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for shared app dir");
 
@@ -343,7 +348,10 @@ RUNNER_TEST_SMACK(privilege_control03_app_label_shared_dir)
  */
 RUNNER_TEST_SMACK(privilege_control04_add_permissions)
 {
-    int result = perm_app_uninstall(APP_ID);
+    int result = 0;
+    DB_BEGIN
+
+    result = perm_app_uninstall(APP_ID);
     RUNNER_ASSERT_MSG(result == 0, "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
 
     result = perm_app_install(APP_ID);
@@ -354,6 +362,8 @@ RUNNER_TEST_SMACK(privilege_control04_add_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
         " perm_app_enable_permissions failed with result: " << result);
 
+    DB_END
+
     // Check if the accesses are realy applied..
     result = test_have_all_accesses(rules_efl);
     RUNNER_ASSERT_MSG(result == 1, "Permissions not added.");
@@ -370,6 +380,8 @@ RUNNER_CHILD_TEST(privilege_control06_revoke_permissions)
     int result;
 
     // Cleanup
+    DB_BEGIN
+
     result = perm_app_uninstall(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == 0, "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
     result = perm_app_uninstall(WGT_PARTNER_APP_ID);
@@ -383,6 +395,11 @@ RUNNER_CHILD_TEST(privilege_control06_revoke_permissions)
     result = perm_app_uninstall(OSP_PLATFORM_APP_ID);
     RUNNER_ASSERT_MSG(result == 0, "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
 
+    // Close transaction to commit uninstallation before further actions
+    DB_END
+
+    DB_BEGIN
+
     // Install test apps
     result = perm_app_install(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == 0, "perm_app_install returned " << result << ". Errno: " << strerror(errno));
@@ -397,6 +414,10 @@ RUNNER_CHILD_TEST(privilege_control06_revoke_permissions)
     result = perm_app_install(OSP_PLATFORM_APP_ID);
     RUNNER_ASSERT_MSG(result == 0, "perm_app_install returned " << result << ". Errno: " << strerror(errno));
 
+    // Close transaction to commit installation before further actions
+    DB_END
+
+    DB_BEGIN
 
     // TEST:
     // Revoke permissions
@@ -419,6 +440,8 @@ RUNNER_CHILD_TEST(privilege_control06_revoke_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
         "Error revoking app permissions. Result: " << result);
 
+    DB_END
+
     // Are all the permissions revoked?
     result = test_have_any_accesses(rules_wgt);
     RUNNER_ASSERT_MSG(result == 0, "Not all permisions revoked.");
@@ -433,6 +456,8 @@ RUNNER_CHILD_TEST(privilege_control06_revoke_permissions)
     result = test_have_any_accesses(rules_osp_platform);
     RUNNER_ASSERT_MSG(result == 0, "Not all permisions revoked.");
 
+    DB_BEGIN
+
     // Cleanup - uninstall test apps
     result = perm_app_uninstall(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == 0, "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
@@ -446,6 +471,8 @@ RUNNER_CHILD_TEST(privilege_control06_revoke_permissions)
     RUNNER_ASSERT_MSG(result == 0, "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
     result = perm_app_uninstall(OSP_PLATFORM_APP_ID);
     RUNNER_ASSERT_MSG(result == 0, "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
+
+    DB_END
 }
 
 
@@ -454,9 +481,13 @@ void set_app_privilege(int line_no,
                        const char** privileges, const char* type,
                        const char* app_path, const char* dac_file,
                        const std::vector< std::vector<std::string> > &rules) {
+
     int result = perm_app_uninstall(app_id);
     RUNNER_ASSERT_MSG(result == 0, "Line: " << line_no <<
             " perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
+
+    DB_BEGIN
+
     result = perm_app_install(app_id);
     RUNNER_ASSERT_MSG(result == 0, "Line: " << line_no <<
             " perm_app_install returned " << result << ". Errno: " << strerror(errno));
@@ -466,6 +497,8 @@ void set_app_privilege(int line_no,
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS, "Line: " << line_no <<
         " Error enabling app permissions. Result: " << result);
 
+    DB_END
+
     result = test_have_all_accesses(rules);
     RUNNER_ASSERT_MSG(result == 1, "Permissions not added.");
 
@@ -553,6 +586,7 @@ RUNNER_TEST(privilege_control11_add_api_feature)
 
     remove_smack_files();
 
+    DB_BEGIN
 
     // argument validation
     result = perm_add_api_feature(APP_TYPE_OSP, NULL, NULL, NULL, 0);
@@ -638,6 +672,7 @@ RUNNER_TEST(privilege_control11_add_api_feature)
         }, NULL, 0);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS, "perm_add_api_feature returned: " << result);
 
+    DB_END
 
     // empty group ids
     result = perm_add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE[12].c_str(), (const char*[]) {"~APP~ b a",NULL},(const gid_t[]) {0,1,2},0);
@@ -683,7 +718,7 @@ RUNNER_TEST(privilege_control01_app_install)
 }
 
 /*
- * Check perm_app_install function
+ * Check perm_app_uninstall function
  */
 RUNNER_TEST(privilege_control07_app_uninstall)
 {
@@ -732,6 +767,8 @@ RUNNER_TEST_SMACK(privilege_control10_app_register_av)
 
     cleaning_smack_app_files();
 
+    DB_BEGIN
+
     // Adding two apps before antivir
     result = perm_app_install(APP_TEST_APP_1);
     RUNNER_ASSERT_MSG(result == 0, "perm_app_install returned " << result << ". Errno: " << strerror(errno));
@@ -743,6 +780,8 @@ RUNNER_TEST_SMACK(privilege_control10_app_register_av)
     result = app_register_av(APP_TEST_AV_1);
     RUNNER_ASSERT_MSG(result == 0, "app_register_av returned " << result << ". Errno: " << strerror(errno));
 
+    DB_END
+
     // Checking added apps accesses
     checkOnlyAvAccess(APP_TEST_AV_1, APP_TEST_APP_1, "app_register_av(APP_TEST_AV_1)");
     checkOnlyAvAccess(APP_TEST_AV_1, APP_TEST_APP_2, "app_register_av(APP_TEST_AV_1)");
@@ -784,6 +823,8 @@ RUNNER_TEST_SMACK(privilege_control11_app_enable_permissions)
     int result;
 
     // Clean up after test:
+    DB_BEGIN
+
     result = perm_app_uninstall(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS, "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
     result = perm_app_install(WGT_APP_ID);
@@ -800,10 +841,14 @@ RUNNER_TEST_SMACK(privilege_control11_app_enable_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
         " Error enabling app permissions. Result: " << result);
 
+    DB_END
+
     // Check if the accesses are realy applied..
     result = test_have_all_accesses(rules2);
     RUNNER_ASSERT_MSG(result == 1, "Permissions not added.");
 
+    DB_BEGIN
+
     // Clean up
     result = perm_app_revoke_permissions(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -817,10 +862,14 @@ RUNNER_TEST_SMACK(privilege_control11_app_enable_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
         " Error enabling app permissions. Result: " << result);
 
+    DB_END
+
     // Check if the accesses are realy applied..
     result = test_have_all_accesses(rules2);
     RUNNER_ASSERT_MSG(result == 1, "Permissions not added.");
 
+    DB_BEGIN
+
     // Clean up
     result = perm_app_revoke_permissions(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -834,10 +883,14 @@ RUNNER_TEST_SMACK(privilege_control11_app_enable_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
         " Error enabling app permissions. Result: " << result);
 
+    DB_END
+
     // Check if the accesses are realy applied..
     result = test_have_all_accesses(rules2_no_r);
     RUNNER_ASSERT_MSG(result == 1, "Permissions not added.");
 
+    DB_BEGIN
+
     // Clean up
     result = perm_app_revoke_permissions(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -852,6 +905,8 @@ RUNNER_TEST_SMACK(privilege_control11_app_enable_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
         " Error enabling app permissions without r. Result: " << result);
 
+    DB_END
+
     // Check if the accesses are realy applied..
     result = test_have_all_accesses(rules2_no_r);
     RUNNER_ASSERT_MSG(result == 1, "Permissions without r not added.");
@@ -865,6 +920,8 @@ RUNNER_TEST_SMACK(privilege_control11_app_enable_permissions)
     result = test_have_all_accesses(rules2);
     RUNNER_ASSERT_MSG(result == 1, "Permissions all not added.");
 
+    DB_BEGIN
+
     // Clean up
     result = perm_app_revoke_permissions(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -879,6 +936,8 @@ RUNNER_TEST_SMACK(privilege_control11_app_enable_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
         " Error enabling app permissions without r. Result: " << result);
 
+    DB_END
+
     // Check if the accesses are realy applied..
     result = test_have_all_accesses(rules2_no_r);
     RUNNER_ASSERT_MSG(result == 1, "Permissions without r not added.");
@@ -892,6 +951,8 @@ RUNNER_TEST_SMACK(privilege_control11_app_enable_permissions)
     result = test_have_all_accesses(rules2_r);
     RUNNER_ASSERT_MSG(result == 1, "Permissions with only r not added.");
 
+    DB_BEGIN
+
     // Clean up
     result = perm_app_revoke_permissions(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -903,12 +964,15 @@ RUNNER_TEST_SMACK(privilege_control11_app_enable_permissions)
     result = perm_app_uninstall(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS, "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
 
+    DB_END
 }
 
 RUNNER_CHILD_TEST(privilege_control11_app_enable_permissions_efl)
 {
     int result;
 
+    DB_BEGIN
+
     // Prepare
     result = perm_app_uninstall(EFL_APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -922,6 +986,8 @@ RUNNER_CHILD_TEST(privilege_control11_app_enable_permissions_efl)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
         "Error enabling app permissions. Result: " << result);
 
+    DB_END
+
     RUNNER_ASSERT_MSG(smack_have_access(EFL_APP_ID,"test_book_efl", "r"),
             "SMACK accesses not granted for EFL_APP");
 
@@ -938,6 +1004,8 @@ RUNNER_CHILD_TEST(privilege_control12_app_disable_permissions_efl)
 {
     int result;
 
+    DB_BEGIN
+
     // Prepare
     result = perm_app_uninstall(EFL_APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -952,6 +1020,8 @@ RUNNER_CHILD_TEST(privilege_control12_app_disable_permissions_efl)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
         "Error enabling app permissions. Result: " << result);
 
+    DB_END
+
     RUNNER_ASSERT_MSG(smack_have_access(EFL_APP_ID,"test_book_efl", "r"),
             "SMACK accesses not granted for EFL_APP");
 
@@ -977,6 +1047,8 @@ RUNNER_TEST(privilege_control12_app_disable_permissions)
 {
     int result;
 
+    DB_BEGIN
+
     // Prepare
     result = perm_app_uninstall(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -994,6 +1066,8 @@ RUNNER_TEST(privilege_control12_app_disable_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
             " Error enabling app permissions. Result: " << result);
 
+    DB_END
+
     // Are all the permissions enabled?
     result = test_have_any_accesses(rules2);
     RUNNER_ASSERT_MSG(result==1, "Not all permisions enabled.");
@@ -1011,6 +1085,8 @@ RUNNER_TEST(privilege_control12_app_disable_permissions)
  * Test - disable some granted permissions leaving non complementary and then disabling those too.
  */
 
+    DB_BEGIN
+
     // Prepare permissions that will not be disabled
     result = perm_app_enable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS, 1);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -1026,6 +1102,8 @@ RUNNER_TEST(privilege_control12_app_disable_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
             "Error disabling app second permissions. Result: " << result);
 
+    DB_END
+
     // Are all second permissions disabled?
     result = test_have_any_accesses(rules2);
     RUNNER_ASSERT_MSG(result!=1, "Not all first permisions disabled.");
@@ -1047,6 +1125,8 @@ RUNNER_TEST(privilege_control12_app_disable_permissions)
  * Test - disable only no r granted permissions.
  */
 
+    DB_BEGIN
+
     // Prepare permissions
     result = perm_app_enable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2_R, 1);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -1057,6 +1137,8 @@ RUNNER_TEST(privilege_control12_app_disable_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
             "Error disabling app no r permissions. Result: " << result);
 
+    DB_END
+
     // Is any r permissions disabled?
     result = test_have_all_accesses(rules2_r);
     RUNNER_ASSERT_MSG(result==1, "Some of r permissions disabled.");
@@ -1098,6 +1180,8 @@ RUNNER_TEST_SMACK(privilege_control13_app_reset_permissions)
  * Test - doing reset and checking if rules exist again.
  */
 
+    DB_BEGIN
+
     result = perm_app_install(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == 0, "perm_app_install returned " << result << ". Errno: " << strerror(errno));
 
@@ -1111,10 +1195,14 @@ RUNNER_TEST_SMACK(privilege_control13_app_reset_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
         "Error reseting app permissions. Result: " << result);
 
+    DB_END
+
     // Are all second permissions not disabled?
     result = test_have_all_accesses(rules2);
     RUNNER_ASSERT_MSG(result == 1, "Not all permissions added.");
 
+    DB_BEGIN
+
     // Disable permissions
     result = perm_app_revoke_permissions(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -1123,6 +1211,7 @@ RUNNER_TEST_SMACK(privilege_control13_app_reset_permissions)
     result = perm_app_uninstall(WGT_APP_ID);
     RUNNER_ASSERT_MSG(result == 0, "perm_app_uninstall returned " << result << ". Errno: " << strerror(errno));
 
+    DB_END
 }
 
 /**
@@ -1466,6 +1555,8 @@ RUNNER_TEST(privilege_control17_appsettings_privilege)
     (void)perm_app_uninstall(APP_1);
     (void)perm_app_uninstall(APP_2);
 
+    DB_BEGIN
+
     //install some app 1
     ret = perm_app_install(APP_1);
     RUNNER_ASSERT_MSG(ret == PC_OPERATION_SUCCESS, "Error in perm_app_install." << ret);
@@ -1485,6 +1576,8 @@ RUNNER_TEST(privilege_control17_appsettings_privilege)
     RUNNER_ASSERT_MSG(ret == PC_OPERATION_SUCCESS,
         " Error enabling app permissions. Result: " << ret);
 
+    DB_END
+
     //check if "app_test" has an RX access to the app "app_1"
     ret = smack_have_access(APP_TEST, APP_1, "rx");
     RUNNER_ASSERT_MSG(ret,"access denied");
@@ -1496,6 +1589,8 @@ RUNNER_TEST(privilege_control17_appsettings_privilege)
     RUNNER_ASSERT_MSG(ret,"access denied to smack label: " << app1_dir_label);
 
 
+    DB_BEGIN
+
     //intstall another app: "app_2"
     ret = perm_app_install(APP_2);
     RUNNER_ASSERT_MSG(ret == PC_OPERATION_SUCCESS, "Error in perm_app_install.");
@@ -1505,6 +1600,8 @@ RUNNER_TEST(privilege_control17_appsettings_privilege)
     ret = perm_app_setup_path(APP_2, APP_2_DIR, APP_PATH_SETTINGS_RW );
     RUNNER_ASSERT_MSG(ret == PC_OPERATION_SUCCESS, "Error in perm_app_setup_path: " << ret);
 
+    DB_END
+
     //check if "app_test" has an RX access to the app "app_2"
     ret = smack_have_access(APP_TEST, APP_2, "rx");
     RUNNER_ASSERT_MSG(ret,"access denies");
@@ -1520,14 +1617,20 @@ RUNNER_TEST(privilege_control17_appsettings_privilege)
     rmdir(APP_1_DIR);
     rmdir(APP_2_DIR);
 
+    DB_BEGIN
+
     (void)perm_app_uninstall(APP_TEST);
     (void)perm_app_uninstall(APP_1);
     (void)perm_app_uninstall(APP_2);
+
+    DB_END
 }
 
 void test_app_setup_path(int line_no, app_path_type_t PATH_TYPE) {
     int result;
 
+    DB_BEGIN
+
     result = perm_app_uninstall(APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS, "Line: " << line_no <<
             " Error in perm_app_uninstall." << result);
@@ -1548,6 +1651,8 @@ void test_app_setup_path(int line_no, app_path_type_t PATH_TYPE) {
     RUNNER_ASSERT_MSG(result == 0, "Line: " << line_no <<
             " perm_app_setup_path() failed");
 
+    DB_END
+
     result = nftw(TEST_NON_APP_DIR, &nftw_check_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
     RUNNER_ASSERT_MSG(result == 0, "Line: " << line_no <<
             " Unable to check Smack labels for non-app dir");
@@ -1586,6 +1691,8 @@ RUNNER_TEST(privilege_control20_early_rules)
 
     unlink(SMACK_RULES_DIR APP_ID);
 
+    DB_BEGIN
+
     perm_app_uninstall(APP_ID);
 
     result = perm_app_install(APP_ID);
@@ -1604,6 +1711,8 @@ RUNNER_TEST(privilege_control20_early_rules)
     result = perm_app_enable_permissions(APP_TEST_APP_1, APP_TYPE_WGT, (const char**) &perm, 1);
     RUNNER_ASSERT_MSG(result == 0, "app_enable_permission failed: " << result);
 
+    DB_END
+
     file = fopen(SMACK_STARTUP_RULES_FILE, "r");
     RUNNER_ASSERT_MSG(file != NULL, "File open failed: " << SMACK_STARTUP_RULES_FILE << " : " << file << ". Errno: " << strerror(errno));
 
index 2e862e1..79e7850 100644 (file)
@@ -114,6 +114,8 @@ RUNNER_TEST_NOSMACK(privilege_control03_app_label_shared_dir_nosmack)
 {
     int result;
 
+    DB_BEGIN
+
     result = perm_app_setup_path(APP_ID, TEST_APP_DIR, APP_PATH_GROUP_RW, APP_ID);
     RUNNER_ASSERT_MSG(result != PC_OPERATION_SUCCESS,
             "perm_app_setup_path should fail here. Result: " << result);
@@ -130,6 +132,8 @@ RUNNER_TEST_NOSMACK(privilege_control03_app_label_shared_dir_nosmack)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
             "perm_app_setup_path() failed. Result: " << result);
 
+    DB_END
+
     result = nftw(TEST_APP_DIR, &nftw_check_labels_app_shared_dir_nosmack, FTW_MAX_FDS, FTW_PHYS);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
             "Unable to check Smack labels for shared app dir");
@@ -442,6 +446,8 @@ RUNNER_TEST_NOSMACK(privilege_control10_app_register_av_nosmack)
 
     cleaning_smack_app_files();
 
+    DB_BEGIN
+
     // Adding two apps before antivir
     result = perm_app_install(APP_TEST_APP_1);
     RUNNER_ASSERT_MSG(result == 0,
@@ -456,6 +462,8 @@ RUNNER_TEST_NOSMACK(privilege_control10_app_register_av_nosmack)
     RUNNER_ASSERT_MSG(result == 0,
             "app_register_av returned " << result << ". Errno: " << strerror(errno));
 
+    DB_END
+
     // Checking added apps accesses
     checkOnlyAvAccessNosmack(APP_TEST_AV_1, APP_TEST_APP_1, "app_register_av(APP_TEST_AV_1)");
     checkOnlyAvAccessNosmack(APP_TEST_AV_1, APP_TEST_APP_2, "app_register_av(APP_TEST_AV_1)");
@@ -505,6 +513,8 @@ RUNNER_TEST_NOSMACK(privilege_control11_app_enable_permissions_nosmack)
     int result;
     std::fstream fs;
 
+    DB_BEGIN
+
     result = perm_app_revoke_permissions(APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
             "Error revoking app permissions. Result: " << result);
@@ -513,6 +523,8 @@ RUNNER_TEST_NOSMACK(privilege_control11_app_enable_permissions_nosmack)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
             "Error enabling app permissions. Result: " << result);
 
+    DB_END
+
     //Check if accesses aren't added
     result = test_have_nosmack_accesses(rules2);
     RUNNER_ASSERT_MSG(result == -1, "Permissions shouldn't be added. Result: " << result);
@@ -541,6 +553,8 @@ RUNNER_TEST_NOSMACK(privilege_control13_app_reset_permissions_nosmack)
 {
     int result;
 
+    DB_BEGIN
+
     // Prepare permissions to reset
     result = perm_app_enable_permissions(APP_ID, APP_TYPE_OTHER, PRIVS2, 1);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -551,6 +565,8 @@ RUNNER_TEST_NOSMACK(privilege_control13_app_reset_permissions_nosmack)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
             "Error reseting app permissions. Result: " << result);
 
+    DB_END
+
     result = test_have_nosmack_accesses(rules2);
     RUNNER_ASSERT_MSG(result == -1, "Permissions shouldn't be changed. Result: " << result);
 
index b936b32..3aa5dc3 100644 (file)
@@ -27,6 +27,7 @@
 #include <dpl/test/test_runner.h>
 #include <privilege-control.h>
 #include <libprivilege-control_test_common.h>
+#include <tests_common.h>
 #include <sys/smack.h>
 
 // ---- Macros and arrays used in stress tests ----
@@ -100,6 +101,8 @@ RUNNER_TEST(privilege_control22_app_installation_1x100)
                   "Unable to clean up Smack labels in: " << TEST_NON_APP_DIR
                   << ". Result: " << result);
 
+    DB_BEGIN
+
     result = perm_app_revoke_permissions(APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
                   "Error in perm_app_revoke_permissions. Result: " << result);
@@ -156,10 +159,14 @@ RUNNER_TEST(privilege_control22_app_installation_1x100)
                   "Error in perm_add_api_feature. Cannot add TEST_WGT_FEATURE: "
                   << TEST_WGT_FEATURE << ". Result: " << result);
 
+    DB_END
+
 
     // Install app loop
     for (int i = 0; i < 100; ++i)
     {
+        DB_BEGIN
+
         // Add application
         result = perm_app_install(APP_ID);
         RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -179,11 +186,15 @@ RUNNER_TEST(privilege_control22_app_installation_1x100)
            "Error in perm_app_enable_permissions from WGT Feature. Loop index: "
            << i << ". Result: " << result);
 
+        DB_END
+
         // add shared dirs
         switch (i%2) // separate odd and even loop runs
         {
         case 0: // Shared dirs: APP_PATH_PRIVATE & APP_PATH_PUBLIC_RO
         {
+            DB_BEGIN
+
             // Add app shared dir - APP_PATH_PRIVATE
             result = perm_app_setup_path(APP_ID, TEST_APP_DIR,
                                          APP_PATH_PRIVATE);
@@ -198,6 +209,8 @@ RUNNER_TEST(privilege_control22_app_installation_1x100)
                              "Error in perm_app_setup_path. Loop index: " << i
                              << ". Result: " << result);
 
+            DB_END
+
             // Verify that some previously installed app does not have any access
             // to APP_ID private label
             result = test_have_any_accesses(rules_to_test_any_access1);
@@ -231,6 +244,8 @@ RUNNER_TEST(privilege_control22_app_installation_1x100)
         }
         case 1: // Shared dirs: APP_PATH_APPSETTING_RW & APP_PATH_GROUP_RW
         {
+            DB_BEGIN
+
             // Add app shared dir - APP_PATH_SETTINGS_RW
             result = perm_app_setup_path(APP_ID, TEST_APP_DIR,
                                          APP_PATH_SETTINGS_RW);
@@ -245,6 +260,8 @@ RUNNER_TEST(privilege_control22_app_installation_1x100)
                              "Error in perm_app_setup_path. Loop index: " << i
                              << ". Result: " << result);
 
+            DB_END
+
             // Get autogenerated App-Setting label
             char *label;
             result = smack_getlabel(TEST_APP_DIR, &label,
@@ -325,6 +342,8 @@ RUNNER_TEST(privilege_control22_app_installation_1x100)
                       << ". Result: " << result);
     } // END Install app loop
 
+    DB_BEGIN
+
     // Uninstall setting app and additional app
     result = perm_app_uninstall(TEST_OSP_FEATURE_APP_ID);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -333,6 +352,8 @@ RUNNER_TEST(privilege_control22_app_installation_1x100)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
                       "Error in perm_app_uninstall. Result: " << result);
 
+    DB_END
+
     // Remove api features
     // TODO: Rewrite removing features
     unlink(FILE_PATH_TEST_OSP_FEATURE);
@@ -393,6 +414,8 @@ RUNNER_TEST(privilege_control23_app_installation2_10x10)
         RUNNER_ASSERT_MSG(result > 0, "Cannot generate name for app nr: " << i);
     }
 
+    DB_BEGIN
+
     // Clear any previously created apps, files, labels and permissions
     for (int i = 0; i < app_count; ++i)
     {
@@ -439,10 +462,14 @@ RUNNER_TEST(privilege_control23_app_installation2_10x10)
                   "Error in perm_add_api_feature. Cannot add TEST_WGT_FEATURE: "
                   << TEST_WGT_FEATURE << ". Result: " << result);
 
+    DB_END
+
 
     // Install apps loop
     for (int i = 0; i < 10; ++i)
     {
+        DB_BEGIN
+
         // Install 10 apps
         for (int j = 0; j < app_count; ++j)
         {
@@ -540,6 +567,8 @@ RUNNER_TEST(privilege_control23_app_installation2_10x10)
                           "Error in perm_app_setup_path. App id: " << app_ids[9]
                           << " Loop index: " << i << ". Result: " << result);
 
+        DB_END
+
         // Verify that some previously installed app does not have
         // any acces to app 0 and app 5 PRIVATE folders
         for (int j = 0; j < app_count; ++j)
@@ -757,6 +786,8 @@ RUNNER_TEST(privilege_control23_app_installation2_10x10)
                        << app_ids[j] << ". Loop index: " << i);
         }
 
+        DB_BEGIN
+
         // Revoke permissions
         for (int j = 0; j < app_count; ++j)
         {
@@ -767,6 +798,8 @@ RUNNER_TEST(privilege_control23_app_installation2_10x10)
                               << ". Result: " << result);
         }
 
+        DB_END
+
         // Check if permissions are removed properly
         for (int j = 0; j < app_count; ++j)
         {
@@ -783,6 +816,8 @@ RUNNER_TEST(privilege_control23_app_installation2_10x10)
             }
         }
 
+        DB_BEGIN
+
         // Remove labels from folders and uninstall all apps
         for (int j = 0; j < app_count; ++j)
         {
@@ -800,6 +835,8 @@ RUNNER_TEST(privilege_control23_app_installation2_10x10)
                               << ". Result: " << result);
         }
 
+        DB_END
+
         // Remove created dirs
         for (int j = 0; j < app_count; ++j)
         {