mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-26 06:32:44 +00:00
This could happen if the machine is pretty busy. I saw intermittent failures on CI and it happened on my machine also while doing other batch job. Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
124 lines
3.1 KiB
C
124 lines
3.1 KiB
C
/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
/*
|
|
Copyright (C) 2018 Red Hat, Inc.
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
/*
|
|
* Test some red_record_ APIs.
|
|
*/
|
|
#include <config.h>
|
|
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "test-glib-compat.h"
|
|
#include "red-record-qxl.h"
|
|
|
|
#define OUTPUT_FILENAME "rec1.txt"
|
|
|
|
static void
|
|
test_record(bool compress)
|
|
{
|
|
RedRecord *rec;
|
|
const char *fn = OUTPUT_FILENAME;
|
|
|
|
g_unsetenv("SPICE_WORKER_RECORD_FILTER");
|
|
if (compress) {
|
|
g_setenv("SPICE_WORKER_RECORD_FILTER", "gzip", 1);
|
|
}
|
|
|
|
// delete possible stale test output
|
|
unlink(fn);
|
|
g_assert_cmpint(access(fn, F_OK), <, 0);
|
|
|
|
// create recorder
|
|
rec = red_record_new(fn);
|
|
g_assert_nonnull(rec);
|
|
|
|
// check file was created by recorder
|
|
g_assert_cmpint(access(fn, F_OK), ==, 0);
|
|
|
|
g_assert_nonnull(red_record_ref(rec));
|
|
red_record_unref(rec);
|
|
|
|
// record something
|
|
red_record_event(rec, 1, 123);
|
|
|
|
red_record_unref(rec);
|
|
|
|
// this code prevents a race between closing the record and using the file
|
|
// in case of a filter is used. red_record_unref flushed data to external
|
|
// program but don't wait. Make sure other program wrote some data
|
|
if (compress) {
|
|
int n;
|
|
for (n = 0; n < 10; ++n) {
|
|
FILE *f = fopen(fn, "rb");
|
|
if (f) {
|
|
long size;
|
|
fseek(f, 0, SEEK_END);
|
|
size = ftell(f);
|
|
fclose(f);
|
|
if (size > 0) {
|
|
break;
|
|
}
|
|
}
|
|
usleep(100000);
|
|
}
|
|
}
|
|
|
|
// check content of the output file
|
|
FILE *f;
|
|
if (!compress) {
|
|
f = fopen(fn, "rb");
|
|
} else {
|
|
f = popen("gzip -dc < " OUTPUT_FILENAME, "r");
|
|
}
|
|
g_assert_nonnull(f);
|
|
|
|
char line[1024];
|
|
int version;
|
|
g_assert_nonnull(fgets(line, sizeof(line), f));
|
|
g_assert_cmpint(sscanf(line, "SPICE_REPLAY %d", &version), ==, 1);
|
|
|
|
int w, t;
|
|
g_assert_nonnull(fgets(line, sizeof(line), f));
|
|
g_assert_cmpint(sscanf(line, "event %*d %d %d", &w, &t), ==, 2);
|
|
g_assert_cmpint(w, ==, 1);
|
|
g_assert_cmpint(t, ==, 123);
|
|
|
|
g_assert_null(fgets(line, sizeof(line), f));
|
|
|
|
if (!compress) {
|
|
fclose(f);
|
|
} else {
|
|
pclose(f);
|
|
}
|
|
|
|
// clean test output file
|
|
unlink(fn);
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
test_record(false);
|
|
// TODO implement on Windows
|
|
#ifndef _WIN32
|
|
test_record(true);
|
|
#endif
|
|
return 0;
|
|
}
|