Skip to content

Commit

Permalink
tests/migration: Enable the migration test on s390x, too
Browse files Browse the repository at this point in the history
We can re-use the s390-ccw bios code to implement a small firmware
for a s390x guest which prints out the "A" and "B" characters and
modifies the memory, as required for the migration test.

[quintela: Converted the compile script to Makefile rules]
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-Id: <1539078677-25396-1-git-send-email-thuth@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
  Fixed up Makefile since the aarch patch sneaked in first
  • Loading branch information
huth authored and dagrh committed Oct 11, 2018
1 parent c02b378 commit 5571dc8
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/Makefile.include
Expand Up @@ -416,6 +416,7 @@ check-qtest-s390x-$(CONFIG_POSIX) += tests/test-filter-redirector$(EXESUF)
check-qtest-s390x-y += tests/drive_del-test$(EXESUF)
check-qtest-s390x-y += tests/virtio-ccw-test$(EXESUF)
check-qtest-s390x-y += tests/cpu-plug-test$(EXESUF)
check-qtest-s390x-y += tests/migration-test$(EXESUF)

check-qtest-generic-y += tests/machine-none-test$(EXESUF)
check-qtest-generic-y += tests/qom-test$(EXESUF)
Expand Down
24 changes: 24 additions & 0 deletions tests/migration-test.c
Expand Up @@ -96,6 +96,17 @@ static void init_bootfile(const char *bootpath, void *content)
fclose(bootfile);
}

#include "tests/migration/s390x/a-b-bios.h"

static void init_bootfile_s390x(const char *bootpath)
{
FILE *bootfile = fopen(bootpath, "wb");
size_t len = sizeof(s390x_elf);

g_assert_cmpint(fwrite(s390x_elf, len, 1, bootfile), ==, 1);
fclose(bootfile);
}

/*
* Wait for some output in the serial output file,
* we get an 'A' followed by an endless string of 'B's
Expand Down Expand Up @@ -443,6 +454,19 @@ static int test_migrate_start(QTestState **from, QTestState **to,
accel, tmpfs, bootpath, uri);
start_address = X86_TEST_MEM_START;
end_address = X86_TEST_MEM_END;
} else if (g_str_equal(arch, "s390x")) {
init_bootfile_s390x(bootpath);
cmd_src = g_strdup_printf("-machine accel=%s -m 128M"
" -name source,debug-threads=on"
" -serial file:%s/src_serial -bios %s",
accel, tmpfs, bootpath);
cmd_dst = g_strdup_printf("-machine accel=%s -m 128M"
" -name target,debug-threads=on"
" -serial file:%s/dest_serial -bios %s"
" -incoming %s",
accel, tmpfs, bootpath, uri);
start_address = S390_TEST_MEM_START;
end_address = S390_TEST_MEM_END;
} else if (strcmp(arch, "ppc64") == 0) {
cmd_src = g_strdup_printf("-machine accel=%s -m 256M -nodefaults"
" -name source,debug-threads=on"
Expand Down
2 changes: 1 addition & 1 deletion tests/migration/Makefile
Expand Up @@ -5,7 +5,7 @@
# See the COPYING file in the top-level directory.
#

TARGET_LIST = i386 aarch64
TARGET_LIST = i386 aarch64 s390x

SRC_PATH = ../..

Expand Down
4 changes: 4 additions & 0 deletions tests/migration/migration-test.h
Expand Up @@ -14,6 +14,10 @@
#define X86_TEST_MEM_START (1 * 1024 * 1024)
#define X86_TEST_MEM_END (100 * 1024 * 1024)

/* S390 */
#define S390_TEST_MEM_START (1 * 1024 * 1024)
#define S390_TEST_MEM_END (100 * 1024 * 1024)

/* PPC */
#define PPC_TEST_MEM_START (1 * 1024 * 1024)
#define PPC_TEST_MEM_END (100 * 1024 * 1024)
Expand Down
24 changes: 24 additions & 0 deletions tests/migration/s390x/Makefile
@@ -0,0 +1,24 @@
# To specify cross compiler prefix, use CROSS_PREFIX=
# $ make CROSS_PREFIX=s390x-linux-gnu-

.PHONY: all clean
all: a-b-bios.h
fwdir=../../../pc-bios/s390-ccw

CFLAGS+=-ffreestanding -fno-delete-null-pointer-checks -fPIE -Os \
-msoft-float -march=z900 -fno-asynchronous-unwind-tables -Wl,-pie \
-Wl,--build-id=none -nostdlib

a-b-bios.h: s390x.elf
echo "$$__note" > header.tmp
xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
mv header.tmp $@

# We use common-page-size=16 to avoid big padding in the ELF file
s390x.elf: a-b-bios.c
$(CROSS_PREFIX)gcc $(CFLAGS) -I$(fwdir) $(fwdir)/start.S \
$(fwdir)/sclp.c -Wl,-zcommon-page-size=16 -o $@ $<
$(CROSS_PREFIX)strip $@

clean:
@rm -rf *.elf *.o
36 changes: 36 additions & 0 deletions tests/migration/s390x/a-b-bios.c
@@ -0,0 +1,36 @@
/*
* S390 guest code used in migration tests
*
* Copyright 2018 Thomas Huth, Red Hat Inc.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/

#define LOADPARM_LEN 8 /* Needed for sclp.h */

#include <libc.h>
#include <s390-ccw.h>
#include <sclp.h>

char stack[0x8000] __attribute__((aligned(4096)));

#define START_ADDRESS (1024 * 1024)
#define END_ADDRESS (100 * 1024 * 1024)

void main(void)
{
unsigned long addr;

sclp_setup();
sclp_print("A");

while (1) {
for (addr = START_ADDRESS; addr < END_ADDRESS; addr += 4096) {
*(volatile char *)addr += 1; /* Change pages */
}
sclp_print("B");
}
}

0 comments on commit 5571dc8

Please sign in to comment.