[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL for-7.1 20/36] tests/unit: Do not reference QemuLogFile directly
From: |
Richard Henderson |
Subject: |
[PULL for-7.1 20/36] tests/unit: Do not reference QemuLogFile directly |
Date: |
Sun, 20 Mar 2022 10:11:19 -0700 |
Use qemu_log_lock/unlock instead of the raw rcu_read.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tests/unit/test-logging.c | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/tests/unit/test-logging.c b/tests/unit/test-logging.c
index 93c6d666e8..fc22bf40b4 100644
--- a/tests/unit/test-logging.c
+++ b/tests/unit/test-logging.c
@@ -110,12 +110,10 @@ static void test_parse_path(gconstpointer data)
static void test_logfile_write(gconstpointer data)
{
- QemuLogFile *logfile;
- QemuLogFile *logfile2;
+ FILE *logfile0, *logfile1;
gchar const *dir = data;
- g_autofree gchar *file_path = NULL;
+ g_autofree gchar *file_path0 = NULL;
g_autofree gchar *file_path1 = NULL;
- FILE *orig_fd;
/*
* Before starting test, set log flags, to ensure the file gets
@@ -124,29 +122,28 @@ static void test_logfile_write(gconstpointer data)
* this is needed.
*/
qemu_set_log(CPU_LOG_TB_OUT_ASM, &error_abort);
- file_path = g_build_filename(dir, "qemu_test_log_write0.log", NULL);
+ file_path0 = g_build_filename(dir, "qemu_test_log_write0.log", NULL);
file_path1 = g_build_filename(dir, "qemu_test_log_write1.log", NULL);
/*
* Test that even if an open file handle is changed,
* our handle remains valid due to RCU.
*/
- qemu_set_log_filename(file_path, &error_abort);
- rcu_read_lock();
- logfile = qatomic_rcu_read(&qemu_logfile);
- orig_fd = logfile->fd;
- g_assert(logfile && logfile->fd);
- fprintf(logfile->fd, "%s 1st write to file\n", __func__);
- fflush(logfile->fd);
+ qemu_set_log_filename(file_path0, &error_abort);
+ logfile0 = qemu_log_lock();
+ g_assert(logfile0);
+ fprintf(logfile0, "%s 1st write to file\n", __func__);
+ fflush(logfile0);
/* Change the logfile and ensure that the handle is still valid. */
qemu_set_log_filename(file_path1, &error_abort);
- logfile2 = qatomic_rcu_read(&qemu_logfile);
- g_assert(logfile->fd == orig_fd);
- g_assert(logfile2->fd != logfile->fd);
- fprintf(logfile->fd, "%s 2nd write to file\n", __func__);
- fflush(logfile->fd);
- rcu_read_unlock();
+ logfile1 = qemu_log_lock();
+ g_assert(logfile1);
+ g_assert(logfile0 != logfile1);
+ fprintf(logfile0, "%s 2nd write to file\n", __func__);
+ fflush(logfile0);
+ qemu_log_unlock(logfile0);
+ qemu_log_unlock(logfile1);
}
static void test_logfile_lock(gconstpointer data)
--
2.25.1
- Re: [PULL for-7.1 04/36] os-posix: Use qemu_log_enabled, (continued)
- [PULL for-7.1 08/36] *: Use fprintf between qemu_log_lock/unlock, Richard Henderson, 2022/03/20
- [PULL for-7.1 07/36] hw/xen: Split out xen_pv_output_msg, Richard Henderson, 2022/03/20
- [PULL for-7.1 16/36] util/log: Remove qemu_log_flush, Richard Henderson, 2022/03/20
- [PULL for-7.1 11/36] exec/translator: Pass the locked filepointer to disas_log hook, Richard Henderson, 2022/03/20
- [PULL for-7.1 14/36] target/nios2: Remove log_cpu_state from reset, Richard Henderson, 2022/03/20
- [PULL for-7.1 25/36] bsd-user: Use qemu_set_log_filename_flags, Richard Henderson, 2022/03/20
- [PULL for-7.1 20/36] tests/unit: Do not reference QemuLogFile directly,
Richard Henderson <=
- [PULL for-7.1 03/36] util/log: Pass Error pointer to qemu_set_log, Richard Henderson, 2022/03/20
- [PULL for-7.1 05/36] util/log: Move qemu_log_lock, qemu_log_unlock out of line, Richard Henderson, 2022/03/20
- [PULL for-7.1 06/36] util/log: Treat qemu_log_lock like trylock, Richard Henderson, 2022/03/20
- [PULL for-7.1 29/36] util/log: Rename logfilename to global_filename, Richard Henderson, 2022/03/20
- [PULL for-7.1 30/36] util/log: Rename qemu_logfile to global_file, Richard Henderson, 2022/03/20