aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-08-23 17:36:59 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-08-25 15:41:12 +0200
commitcae1fcac20d21b736d4c77985b8e11775711a563 (patch)
tree9b57d9556d9d793a393fad91ff084efeea118d4c
parent9318dc4c1801c2aabfd2761755bcd53796d5ee0e (diff)
downloadhardware_replicant_libsamsung-ipc-cae1fcac20d21b736d4c77985b8e11775711a563.tar.gz
hardware_replicant_libsamsung-ipc-cae1fcac20d21b736d4c77985b8e11775711a563.tar.bz2
hardware_replicant_libsamsung-ipc-cae1fcac20d21b736d4c77985b8e11775711a563.zip
tests: open_android_modem_partition: cleanup after creating file
Without that fix, the file being created isn't deleted at the end of the test, so over time the leftover files accumulate in /tmp. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--samsung-ipc/tests/partitions/android.c79
1 files changed, 78 insertions, 1 deletions
diff --git a/samsung-ipc/tests/partitions/android.c b/samsung-ipc/tests/partitions/android.c
index 2314d2b..7b067e9 100644
--- a/samsung-ipc/tests/partitions/android.c
+++ b/samsung-ipc/tests/partitions/android.c
@@ -42,6 +42,59 @@ static char const * const dummy_modem_image_paths[] = {
NULL
};
+int delete_dummy_modem_image(struct ipc_client *client,
+ __attribute__((unused)) const char * const path)
+{
+ int rc;
+ char *endp;
+ char *dir;
+
+ rc = unlink(path);
+ if (rc == -1) {
+ rc = errno;
+ if (rc != ENOENT) {
+ ipc_client_log(client,
+ "%s: unlink %s failed with error %d: %s",
+ __func__, path, rc, strerror(rc));
+ errno = rc;
+ return -1;
+ }
+ }
+
+ endp = strrchr(path, '/');
+
+ dir = malloc(endp - path + 1);
+ if (dir == NULL) {
+ rc = errno;
+ ipc_client_log(client,
+ "%s: calloc failed with error %d: %s",
+ __func__, rc, strerror(rc));
+ errno = rc;
+ return -1;
+
+ }
+
+ memcpy(dir, path, endp - path);
+ dir[endp - path] = '\0';
+
+ rc = rmdir(dir);
+ if (rc == -1) {
+ rc = errno;
+ if (rc != ENOENT) {
+ ipc_client_log(client,
+ "%s: rmdir %s failed with error %d: %s",
+ __func__, dir, rc, strerror(rc));
+
+ free(dir);
+ errno = rc;
+ return -1;
+ }
+ }
+
+ free(dir);
+ return 0;
+}
+
int create_dummy_modem_image(struct ipc_client *client,
__attribute__((unused)) const char * const path)
@@ -52,10 +105,12 @@ int create_dummy_modem_image(struct ipc_client *client,
rc = mkdir("/tmp/", 0755);
if (rc == -1) {
rc = errno;
- if (rc != EEXIST)
+ if (rc != EEXIST) {
ipc_client_log(client,
"%s: mkdir %s failed with error %d: %s",
__func__, "/tmp/", rc, strerror(rc));
+ return -1;
+ }
}
rc = mkdir("/tmp/libsamsung-ipc.55f4731d2e11e85bd889/", 0755);
@@ -67,6 +122,7 @@ int create_dummy_modem_image(struct ipc_client *client,
__func__,
"/tmp/libsamsung-ipc.55f4731d2e11e85bd889/",
rc, strerror(rc));
+ return -1;
}
}
@@ -79,6 +135,7 @@ int create_dummy_modem_image(struct ipc_client *client,
__func__,
"/tmp/libsamsung-ipc.55f4731d2e11e85bd889/modem.img",
rc, strerror(rc));
+ goto error;
}
rc = close(fd);
@@ -89,9 +146,19 @@ int create_dummy_modem_image(struct ipc_client *client,
__func__,
"/tmp/libsamsung-ipc.55f4731d2e11e85bd889/modem.img",
rc, strerror(rc));
+ goto error;
}
return 0;
+
+error:
+ rc = delete_dummy_modem_image(
+ client, "/tmp/libsamsung-ipc.55f4731d2e11e85bd889/modem.img");
+ if (rc == -1)
+ ipc_client_log(client,
+ "%s: delete_dummy_modem_image %s failed with error -1",
+ __func__);
+ return -1;
}
int test_open_android_modem_partition(struct ipc_client *client)
@@ -131,5 +198,15 @@ int test_open_android_modem_partition(struct ipc_client *client)
return -1;
}
+ rc = delete_dummy_modem_image(
+ client, "/tmp/libsamsung-ipc.55f4731d2e11e85bd889/modem.img");
+ if (rc == -1) {
+ rc = errno;
+ ipc_client_log(client,
+ "%s: delete_dummy_modem_image() failed with errror %d: %s\n",
+ __func__, rc, strerror(rc));
+ return -1;
+ }
+
return 0;
}