Skip to content

Commit a0ce318

Browse files
committed
test: Use rz_file_tmpdir to have temporary dir
1 parent 0435127 commit a0ce318

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

test/integration/test_cpu_platform_profiles.c

+16-7
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ bool test_cpu_profiles() {
3131
mu_assert_eq(item->offset, 0x00000005, "Flag PORTB not found");
3232

3333
// 3. Save into the project
34-
if (!rz_file_is_directory(".tmp" RZ_SYS_DIR)) {
35-
mu_assert_true(rz_sys_mkdir(".tmp/"), "create tmp directory");
36-
}
37-
RzProjectErr err = rz_project_save_file(core, ".tmp/cpu_profile.rzdb", true);
34+
char *tmpdir = rz_file_tmpdir();
35+
char *project_file = rz_file_path_join(tmpdir, "cpu_profile.rzdb");
36+
RzProjectErr err = rz_project_save_file(core, project_file, true);
3837
mu_assert_eq(err, RZ_PROJECT_ERR_SUCCESS, "project save err");
38+
free(project_file);
3939

4040
// 4. Close the file
4141
rz_core_file_close(file);
@@ -48,7 +48,9 @@ bool test_cpu_profiles() {
4848
// 6. Load the previously saved project
4949
RzSerializeResultInfo *res = rz_serialize_result_info_new();
5050
mu_assert_notnull(res, "result info new");
51-
err = rz_project_load_file(core, ".tmp/cpu_profile.rzdb", true, res);
51+
project_file = rz_file_path_join(tmpdir, "cpu_profile.rzdb");
52+
err = rz_project_load_file(core, project_file, true, res);
53+
free(project_file);
5254
rz_serialize_result_info_free(res);
5355
mu_assert_eq(err, RZ_PROJECT_ERR_SUCCESS, "project load err");
5456

@@ -58,6 +60,7 @@ bool test_cpu_profiles() {
5860
item = rz_flag_get(core->flags, "PORTB");
5961
mu_assert_eq(item->offset, 0x00000005, "Flag PORTB not found");
6062

63+
free(tmpdir);
6164
rz_core_free(core);
6265
mu_end;
6366
}
@@ -85,8 +88,11 @@ bool test_platform_profiles() {
8588
mu_assert_streq(comment, "Broadcom Serial Controller 1 (BSC)", "Comment unequal!");
8689

8790
// 3. Save into the project
88-
RzProjectErr err = rz_project_save_file(core, ".tmp/cpu_platform.rzdb", true);
91+
char *tmpdir = rz_file_tmpdir();
92+
char *project_file = rz_file_path_join(tmpdir, "cpu_platform.rzdb");
93+
RzProjectErr err = rz_project_save_file(core, project_file, true);
8994
mu_assert_eq(err, RZ_PROJECT_ERR_SUCCESS, "project save err");
95+
free(project_file);
9096

9197
// 4. Close the file
9298
rz_core_file_close(file);
@@ -99,7 +105,9 @@ bool test_platform_profiles() {
99105
// 6. Load the previously saved project
100106
RzSerializeResultInfo *res = rz_serialize_result_info_new();
101107
mu_assert_notnull(res, "result info new");
102-
err = rz_project_load_file(core, ".tmp/cpu_platform.rzdb", true, res);
108+
project_file = rz_file_path_join(tmpdir, "cpu_platform.rzdb");
109+
err = rz_project_load_file(core, project_file, true, res);
110+
free(project_file);
103111
rz_serialize_result_info_free(res);
104112
mu_assert_eq(err, RZ_PROJECT_ERR_SUCCESS, "project load err");
105113

@@ -109,6 +117,7 @@ bool test_platform_profiles() {
109117
item = rz_flag_get(core->flags, "AUX_MU_IER_REG");
110118
mu_assert_eq(item->offset, 0x7e215044, "Flag AUX_MU_IER_REG not found");
111119

120+
free(tmpdir);
112121
rz_core_free(core);
113122
mu_end;
114123
}

test/integration/test_open_analyse_save_load_project.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bool test_open_analyse_save() {
2626
eprintf("functions count = %d\n", rz_list_length(functionsold));
2727

2828
// 3. Remove the function
29-
const char* fcnname = "fcn.0000ebe0";
29+
const char *fcnname = "fcn.0000ebe0";
3030
RzAnalysisFunction *fcn = rz_analysis_get_function_byname(core->analysis, fcnname);
3131
mu_assert_notnull(fcn, "find function");
3232
rz_analysis_function_delete(fcn);
@@ -37,11 +37,11 @@ bool test_open_analyse_save() {
3737
size_t functions_count_expect = rz_list_length(functions);
3838

3939
// 4. Save into the project
40-
if (!rz_file_is_directory(".tmp" RZ_SYS_DIR)) {
41-
mu_assert_true(rz_sys_mkdir(".tmp/"), "create tmp directory");
42-
}
43-
RzProjectErr err = rz_project_save_file(core, ".tmp/test_open_analyse.rzdb", true);
40+
char *tmpdir = rz_file_tmpdir();
41+
char *project_file = rz_file_path_join(tmpdir, "test_open_analyse.rzdb");
42+
RzProjectErr err = rz_project_save_file(core, project_file, true);
4443
mu_assert_eq(err, RZ_PROJECT_ERR_SUCCESS, "project save err");
44+
free(project_file);
4545

4646
// 5. Close the file
4747
rz_core_file_close(file);
@@ -54,8 +54,10 @@ bool test_open_analyse_save() {
5454
// 7. Load the previously saved project
5555
RzSerializeResultInfo *res = rz_serialize_result_info_new();
5656
mu_assert_notnull(res, "result info new");
57-
err = rz_project_load_file(core, ".tmp/test_open_analyse.rzdb", true, res);
57+
project_file = rz_file_path_join(tmpdir, "test_open_analyse.rzdb");
58+
err = rz_project_load_file(core, project_file, true, res);
5859
mu_assert_eq(err, RZ_PROJECT_ERR_SUCCESS, "project load err");
60+
free(project_file);
5961

6062
// 8. Export the function list
6163
RzList *functions_load = rz_analysis_function_list(core->analysis);
@@ -65,6 +67,7 @@ bool test_open_analyse_save() {
6567
mu_assert_eq(rz_list_length(functions_load), functions_count_expect, "compare functions list");
6668

6769
// 10. Exit
70+
free(tmpdir);
6871
rz_serialize_result_info_free(res);
6972
rz_core_free(core);
7073
mu_end;

0 commit comments

Comments
 (0)