+RUNNER_CHILD_TEST_SMACK(security_manager_03_set_label_from_binary)
+{
+ const char *const testBinaryPath = LABELLED_BINARY_PATH;
+ const char *const expectedLabel = USER_APP_ID;
+ int result;
+ char *label = NULL;
+ CStringPtr labelPtr;
+
+ result = security_manager_set_process_label_from_binary(testBinaryPath);
+ RUNNER_ASSERT_MSG_BT(result == SECURITY_MANAGER_SUCCESS,
+ "security_manager_set_process_label_from_binary(" <<
+ testBinaryPath << ") failed. Result: " << result);
+
+ result = smack_new_label_from_self(&label);
+ RUNNER_ASSERT_MSG_BT(result >= 0,
+ " Error getting current process label");
+ RUNNER_ASSERT_MSG_BT(label != NULL,
+ " Process label is not set");
+ labelPtr.reset(label);
+
+ result = strcmp(expectedLabel, label);
+ RUNNER_ASSERT_MSG_BT(result == 0,
+ " Process label is incorrect. Expected: \"" << expectedLabel << "\" Actual: \""
+ << label << "\"");
+}
+
+RUNNER_CHILD_TEST_NOSMACK(security_manager_03_set_label_from_binary_nosmack)
+{
+ const char *const testBinaryPath = LABELLED_BINARY_PATH;
+ int result;
+
+ result = security_manager_set_process_label_from_binary(testBinaryPath);
+ RUNNER_ASSERT_MSG_BT(result == SECURITY_MANAGER_SUCCESS,
+ "security_manager_set_process_label_from_binary(" <<
+ testBinaryPath << ") failed. Result: " << result);
+}
+
+RUNNER_CHILD_TEST_SMACK(security_manager_04_set_label_from_appid)
+{
+ const char *const app_id = "sm_test_app_id_set_label_from_appid";
+ const char *const pkg_id = "sm_test_pkg_id_set_label_from_appid";
+ const char *const expected_label = USER_APP_ID;
+ char *label = NULL;
+ CStringPtr labelPtr;
+ int result;
+
+ uninstall_app(app_id, pkg_id, false, true);
+ install_app(app_id, pkg_id);
+
+ result = security_manager_set_process_label_from_appid(app_id);
+ RUNNER_ASSERT_MSG_BT(result == SECURITY_MANAGER_SUCCESS,
+ "security_manager_set_process_label_from_appid(" <<
+ app_id << ") failed. Result: " << result);
+
+ result = smack_new_label_from_self(&label);
+ RUNNER_ASSERT_MSG_BT(result >= 0,
+ " Error getting current process label");
+ RUNNER_ASSERT_MSG_BT(label != NULL,
+ " Process label is not set");
+ labelPtr.reset(label);
+
+ result = strcmp(expected_label, label);
+ RUNNER_ASSERT_MSG_BT(result == 0,
+ " Process label is incorrect. Expected: \"" << expected_label <<
+ "\" Actual: \"" << label << "\"");
+
+ uninstall_app(app_id, pkg_id, true, true);
+}
+
+RUNNER_CHILD_TEST_NOSMACK(security_manager_04_set_label_from_appid_nosmack)
+{
+ const char *const app_id = "sm_test_app_id_set_label_from_appid";
+ const char *const pkg_id = "sm_test_pkg_id_set_label_from_appid";
+ int result;
+
+ uninstall_app(app_id, pkg_id, false, true);
+ install_app(app_id, pkg_id);
+
+ result = security_manager_set_process_label_from_appid(app_id);
+ RUNNER_ASSERT_MSG_BT(result == SECURITY_MANAGER_SUCCESS,
+ "security_manager_set_process_label_from_appid(" <<
+ app_id << ") failed. Result: " << result);
+
+ uninstall_app(app_id, pkg_id, true, true);
+}
+