qtest fixes and alternative IRQ intercept proposal
cover qtest fixes and alternative IRQ intercept proposal
Anthony,
here are some random qtest patches, for incorporation in your series or just as food for thought.
Patch 1 makes the tests fail with an assertion failure if libqtest screws up, rather than just having them sit waiting for a response that will never come.
Patch 2 makes "-qtest stdio" a bit more useful.
Patch 3 is a fix for the Makefile, which happens when tests fail.
Patch 4 is a fix for some bogus code in the rtc test that GCC flagged.
Patch 5 actually implements the idea of not using TCG for the CPU threads. Since this is quite easy to do I don't see why not (for example, would you like to have qtest depend on TCG if your disable-tcg series ever lands?).
Patches 6-9 replace the qtest interrupt controller with interception on the qtest side. The idea is to pass a device to a qtest command. qtest then patches the qemu_irqs for the gpio pins so that, when they trigger, the notification is sent on the qtest chardev. Right you can attach only to one device, and only to either the output side or the input side. But even this is already enormously more flexible and IMO cleaner than the qtest_interrupt_controller.
Attaching to the output side would usually be better for unit testing of a single device, but not many devices on a PC register gpio pins. Luckily, one such device is (on the input side) the ioapic, so that irq_intercept_in("ioapic") provides the exact same behavior as the qtest_interrupt_controller in your code.
In the future, once gpio pins are converted Pin properties, the commands could be modified like
irq_intercept_{in,out} QOM-PATH PROPERTY NUM
which maps the given property to a qtest interrupt number. In the meanwhile, the interface works nicely and provides a bit more QOM dogfooding (as shown by the need for patch 6).
All patches except patch 6 are meant to be squashed in yours; sending them this way is easier for review and just one "git rebase -i" apart from the desired result. Hence the scant commit messages. :)
Paolo Bonzini (9):
qtest: always send a response
qtest: enable echo
qtest: fix Makefile
rtc-test: fix set_alarm_time
qtest: do not use TCG CPU threads
pc: attach ioapic to the QOM composition tree
qtest: IRQ interception infrastructure
libqtest: add IRQ intercept commands
rtc-test: add IRQ intercept
cpu-exec.c | 4 -- cpus.c | 62 ++++++++++++++++++++++++++++++++-- hw/irq.c | 18 ++++++++++ hw/irq.h | 3 ++ hw/pc_piix.c | 9 +++-- qtest.c | 100 +++++++++++++++++++++++++++++++++++++---------------- qtest.h | 2 - tests/Makefile | 2 +- tests/libqtest.c | 12 ++++++ tests/libqtest.h | 6 +++ tests/rtc-test.c | 23 +++---------- 11 files changed, 179 insertions(+), 62 deletions(-)
Signature · 1 line
1.7.7.1
RFC PATCH 1/9 qtest: always send a response
--- qtest.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
qtest.c +2 -1
@@ -241,7 +241,8 @@ static void qtest_process_command(CharDriverState *chr, gchar **words)qtest_send_prefix (chr);qtest_send (chr,"OK\n" ); }else { -fprintf (stderr,"Unknown command `%s'\n" , words[0 ]); +qtest_send_prefix (chr); +qtest_send (chr,"FAIL Unknown command `%s'\n" , words[0 ]); } }
Signature · 1 line
1.7.7.1
RFC PATCH 2/9 qtest: enable echo
In reply to Paolo Bonzini--- qtest.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
qtest.c +1 -0
@@ -341,6 +341,7 @@ int qtest_init(void) chr =qemu_chr_new ("qtest" , qtest_chrdev,NULL );qemu_chr_add_handlers (chr, qtest_can_read, qtest_read, qtest_event, chr); +qemu_chr_fe_set_echo (chr, true); inbuf =g_string_new ("" );
Signature · 1 line
1.7.7.1
RFC PATCH 3/9 qtest: fix Makefile
In reply to Paolo Bonzini--- tests/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tests/Makefile +1 -1
@@ -77,7 +77,7 @@ check-qtest-%: $(HW_TESTS) @for test in $^; do \ arch=`echo $@ | cut -f3- -d-`; \ echo "Running '$$test' with qemu-system-$$arch..."; \ - $(SRC_PATH)/scripts/qtest $$arch-softmmu/qemu-system-$$arch $$test || exit $?; \ + $(SRC_PATH)/scripts/qtest $$arch-softmmu/qemu-system-$$arch $$test || exit $$?; \ done check-qtest: $(patsubst %,check-qtest-%, $(TARGETS))
Signature · 1 line
1.7.7.1
RFC PATCH 4/9 rtc-test: fix set_alarm_time
In reply to Paolo BonziniGCC (correctly) reports uninitialized variables.
--- tests/rtc-test.c | 22 ++++------------------ 1 files changed, 4 insertions(+), 18 deletions(-)
tests/rtc-test.c +4 -18
@@ -195,26 +195,12 @@ static void dec_check_time(void)static void set_alarm_time (struct tm *tm) { -int sec, min, hour; -int hour_offset; - - sec = tm->tm_sec -1 ; +int sec; + sec = tm->tm_sec;if ((cmos_read (RTC_REG_B ) ®_B_DM ) ==0 ) { sec =dec2bcd (sec); - min =dec2bcd (min); - hour =dec2bcd (hour); - hour_offset =80 ; - }else { - hour_offset =0x80 ; - } - -if ((cmos_read (RTC_REG_B ) ®_B_24H ) !=0 ) { -if (hour >=12 ) { - hour -=12 ; - hour += hour_offset; - } }cmos_write (RTC_SECONDS_ALARM , sec);
@@ -236,11 +222,11 @@ static void alarm_time(void)g_assert (!get_irq (RTC_ISA_IRQ )); - now.tm_sec +=1 ; + now.tm_sec = (now.tm_sec +2 ) %60 ;set_alarm_time (&now);cmos_write (RTC_REG_B ,cmos_read (RTC_REG_B ) |REG_B_AIE ); -for (i =0 ; i <1 + wiggle; i++) { +for (i =0 ; i <2 + wiggle; i++) {if (get_irq (RTC_ISA_IRQ )) {break ; }
Signature · 1 line
1.7.7.1
RFC PATCH 5/9 qtest: do not use TCG CPU threads
In reply to Paolo Bonzini--- cpu-exec.c | 4 --- cpus.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 7 deletions(-)
cpu-exec.c +0 -4
@@ -189,10 +189,6 @@ int cpu_exec(CPUState *env)uint8_t *tc_ptr;unsigned long next_tb; -if (qtest_enabled ()) { - env->halted =1 ; - } -if (env->halted) {if (!cpu_has_work (env)) {return EXCP_HALTED ;
cpus.c +59 -3
93 lines not on this page · raw message
Signature · 1 line
1.7.7.1
Re: [Qemu-devel] [RFC PATCH 5/9] qtest: do not use TCG CPU threads
Am 18.01.2012 11:33, schrieb Paolo Bonzini:
Quoted 15 lines
Signed-off-by Paolo Bonzini <[email protected]>--- cpu-exec.c | 4 --- cpus.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 7 deletions(-)cpus.c +1
-2-if (kvm_enabled () && !env->thread_kicked) { +if (!tcg_enabled () && !env->thread_kicked) { -if (kvm_enabled ()) {
cpus.c
Quoted 10 lines
cpus.c +4
-1+if (!tcg_enabled ()) {if (kvm_enabled ()) {qemu_kvm_start_vcpu (env); - }else { + }else if (tcg_enabled ()) {qemu_tcg_init_vcpu (env); + }else { +qemu_dummy_start_vcpu (env); }
Did you keep Xen in mind when changing the logic?
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [RFC PATCH 5/9] qtest: do not use TCG CPU threads
Quoted 12 lines · Andreas Färber
Quoted 12 lines
- if (kvm_enabled()&& !env->thread_kicked) {
+ if (!tcg_enabled()&& !env->thread_kicked) { - if (kvm_enabled()) { + if (!tcg_enabled()) { if (kvm_enabled()) { qemu_kvm_start_vcpu(env); - } else { + } else if (tcg_enabled()) { qemu_tcg_init_vcpu(env); + } else { + qemu_dummy_start_vcpu(env); }
Quoted 1 line
Did you keep Xen in mind when changing the logic?
Yes, though I didn't test it. There's no reason why Xen should depend on any TCG code.
Paolo
RFC PATCH 6/9 pc: attach ioapic to the QOM composition tree
In reply to Paolo Bonzini--- hw/pc_piix.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
hw/pc_piix.c +5 -2
@@ -54,7 +54,7 @@ static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };static const int ide_iobase2[MAX_IDE_BUS ] = {0x3f6 ,0x376 };static const int ide_irq[MAX_IDE_BUS ] = {14 ,15 }; -static void ioapic_init (GSIState *gsi_state) +static DeviceState *ioapic_init (GSIState *gsi_state) {DeviceState *dev;SysBusDevice *d;
@@ -68,6 +68,7 @@ static void ioapic_init(GSIState *gsi_state)for (i =0 ; i <IOAPIC_NUM_PINS ; i++) { gsi_state->ioapic_irq[i] =qdev_get_gpio_in (dev, i); } +return dev; }/* PC hardware initialisation */
@@ -168,7 +169,9 @@ static void pc_init1(MemoryRegion *system_memory, gsi_state->i8259_irq[i] = i8259[i]; }if (pci_enabled) { -ioapic_init (gsi_state); + dev =ioapic_init (gsi_state); +qdev_property_add_child (qdev_resolve_path ("/i440fx/piix3" ,NULL ), +"ioapic" , dev,NULL ); }pc_register_ferr_irq (gsi[13 ]);
Signature · 1 line
1.7.7.1
Re: [Qemu-devel] [RFC PATCH 6/9] pc: attach ioapic to the QOM composition tree
Quoted 27 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>--- hw/pc_piix.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)hw/pc_piix.c +2
-1@@ -54,7 +54,7 @@ static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };static const int ide_iobase2[MAX_IDE_BUS ] = {0x3f6 ,0x376 };static const int ide_irq[MAX_IDE_BUS ] = {14 ,15 }; -static void ioapic_init (GSIState *gsi_state) +static DeviceState *ioapic_init (GSIState *gsi_state) {DeviceState *dev;SysBusDevice *d;@@ -68,6 +68,7 @@ static void ioapic_init(GSIState *gsi_state)for (i =0 ; i <IOAPIC_NUM_PINS ; i++) { gsi_state->ioapic_irq[i] =qdev_get_gpio_in (dev, i); } +return dev; }/* PC hardware initialisation */
hw/pc_piix.c static void pc_init1(MemoryRegion *system_memory, · line 174
Quoted 7 lines
hw/pc_piix.c +3
-1@@ -168,7 +169,9 @@ static void pc_init1(MemoryRegion *system_memory, gsi_state->i8259_irq[i] = i8259[i]; }if (pci_enabled) { -ioapic_init (gsi_state); + dev =ioapic_init (gsi_state); +qdev_property_add_child (qdev_resolve_path ("/i440fx/piix3" ,NULL ), +"ioapic" , dev,NULL );
That's not true. The IOAPIC was a separate IC, not part of the PIIX3. It should be assigned to the board if you want to do it correctly. :)
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
RFC PATCH 7/9 qtest: IRQ interception infrastructure
In reply to Paolo Bonzini--- hw/irq.c | 18 +++++++++++ hw/irq.h | 3 ++ hw/pc_piix.c | 2 - qtest.c | 96 ++++++++++++++++++++++++++++++++++++++++----------------- qtest.h | 2 - 5 files changed, 88 insertions(+), 33 deletions(-)
hw/irq.c +17 -0
@@ -104,3 +104,20 @@ qemu_irq *qemu_irq_proxy(qemu_irq **target, int n) {return qemu_allocate_irqs (proxy_irq_handler, target, n); } + +void qemu_irq_intercept_in (qemu_irq *gpio_in,qemu_irq_handler handler,int n) +{ +int i; +qemu_irq *old_irqs =qemu_allocate_irqs (NULL ,NULL , n); +for (i =0 ; i < n; i++) { + *old_irqs[i] = *gpio_in[i]; + gpio_in[i]->handler = handler; + gpio_in[i]->opaque = old_irqs; + } +} + +void qemu_irq_intercept_out (qemu_irq **gpio_out,qemu_irq_handler handler,int n) +{ +qemu_irq *old_irqs = *gpio_out; + *gpio_out =qemu_allocate_irqs (handler, old_irqs, n); +}
hw/irq.h +5 -0
@@ -38,4 +38,9 @@ qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2);*/ qemu_irq *qemu_irq_proxy (qemu_irq **target,int n); +/* For internal use in qtest. Similar to qemu_irq_split, but operating +on an existing vector of qemu_irq. */ +void qemu_irq_intercept_in (qemu_irq *gpio_in,qemu_irq_handler handler,int n); +void qemu_irq_intercept_out (qemu_irq **gpio_out,qemu_irq_handler handler,int n); +#endif
hw/pc_piix.c +0 -2
@@ -158,8 +158,6 @@ static void pc_init1(MemoryRegion *system_memory,if (xen_enabled ()) { i8259 =xen_interrupt_controller_init (); - }else if (qtest_enabled ()) { - i8259 =qtest_interrupt_controller_init (); }else { cpu_irq =pc_allocate_cpu_irq (); i8259 =i8259_init (isa_bus, cpu_irq[0 ]);
qtest.c +68 -29
139 lines not on this page · raw message
qtest.h +0 -2
@@ -32,6 +32,4 @@ static inline int qtest_available(void)int qtest_init (void ); -qemu_irq *qtest_interrupt_controller_init (void ); -#endif
Signature · 1 line
1.7.7.1
RFC PATCH 8/9 libqtest: add IRQ intercept commands
In reply to Paolo Bonzini--- tests/libqtest.c | 12 ++++++++++++ tests/libqtest.h | 6 ++++++ 2 files changed, 18 insertions(+), 0 deletions(-)
tests/libqtest.c +12 -0
@@ -235,6 +235,18 @@ bool qtest_get_irq(QTestState *s, int num)return s->irq_level[num]; } +void qtest_irq_intercept_out (QTestState *s,const char *qom_path) +{ +qtest_sendf (s,"irq_intercept_out %s\n" , qom_path); +qtest_rsp (s,0 ); +} + +void qtest_irq_intercept_in (QTestState *s,const char *qom_path) +{ +qtest_sendf (s,"irq_intercept_in %s\n" , qom_path); +qtest_rsp (s,0 ); +} +static void qtest_out (QTestState *s,const char *cmd,uint16_t addr,uint32_t value) {qtest_sendf (s,"%s 0x%x 0x%x\n" , cmd, addr, value);
tests/libqtest.h +6 -0
@@ -26,6 +26,10 @@ void qtest_quit(QTestState *s);bool qtest_get_irq (QTestState *s,int num); +void qtest_irq_intercept_in (QTestState *s,const char *string); + +void qtest_irq_intercept_out (QTestState *s,const char *string); +void qtest_outb (QTestState *s,uint16_t addr,uint8_t value);void qtest_outw (QTestState *s,uint16_t addr,uint16_t value);
@@ -51,6 +55,8 @@ void qtest_add_func(const char *str, void (*fn)); )#define get_irq (num) qtest_get_irq(global_qtest, (num)) +#define irq_intercept_in (num) qtest_irq_intercept_in(global_qtest, (num)) +#define irq_intercept_out (num) qtest_irq_intercept_out(global_qtest, (num))#define outb (addr, val) qtest_outb(global_qtest, (addr), (val))#define outw (addr, val) qtest_outw(global_qtest, (addr), (val))#define outl (addr, val) qtest_outl(global_qtest, (addr), (val))
Signature · 1 line
1.7.7.1
RFC PATCH 9/9 rtc-test: add IRQ intercept
In reply to Paolo Bonzini--- tests/rtc-test.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
tests/rtc-test.c +1 -0
@@ -249,6 +249,7 @@ int main(int argc, char **argv)/* These tests only work on i386 and x86_64 */ if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) { s =qtest_start ("-vnc none" ); +qtest_irq_intercept_in (s,"ioapic" );qtest_add_func ("/rtc/bcd/check-time" , bcd_check_time);qtest_add_func ("/rtc/dec/check-time" , dec_check_time);
Signature · 1 line
1.7.7.1
[Qemu-devel] [RFC PATCH 10/9] qtest: add clock management
In reply to Paolo BonziniThis patch combines qtest and -icount together to turn the vm_clock into a source that can be fully managed by the client. To this end new commands clock_step and clock_set are added. Hooking them with libqtest is left as an exercise to the reader.
--- cpus.c | 20 ++++++++++++++++++++ cpus.h | 2 ++ qemu-timer.c | 2 +- qemu-timer.h | 1 + qtest.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletions(-)
cpus.c +20 -0
@@ -34,6 +34,7 @@#include "qemu-thread.h" #include "cpus.h" +#include "qtest.h" #include "main-loop.h" #ifndef _WIN32
@@ -238,6 +239,20 @@ static void icount_warp_rt(void *opaque) vm_clock_warp_start =-1 ; } +void qtest_clock_warp (int64_t dest) +{ +int64_t clock =qemu_get_clock_ns (vm_clock); +assert (qtest_enabled ()); +while (clock < dest) { +int64_t deadline =qemu_clock_deadline (vm_clock); +int64_t warp =MIN (dest - clock, deadline); + qemu_icount_bias += warp; +qemu_run_timers (vm_clock); + clock =qemu_get_clock_ns (vm_clock); + } +qemu_notify_event (); +} +void qemu_clock_warp (QEMUClock *clock) {int64_t deadline;
@@ -264,6 +279,11 @@ void qemu_clock_warp(QEMUClock *clock)return ; } +if (qtest_enabled ()) { +/* When testing, qtest commands advance icount. */ +return ; + } + vm_clock_warp_start =qemu_get_clock_ns (rt_clock); deadline =qemu_clock_deadline (vm_clock);if (deadline >0 ) {
cpus.h +2 -0
@@ -11,6 +11,8 @@ void cpu_synchronize_all_states(void);void cpu_synchronize_all_post_reset (void );void cpu_synchronize_all_post_init (void ); +void qtest_clock_warp (int64_t dest); +/* vl.c */ extern int smp_cores;extern int smp_threads;
qemu-timer.c +1 -1
@@ -397,7 +397,7 @@ int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time)return qemu_timer_expired_ns (timer_head, current_time * timer_head->scale); } -static void qemu_run_timers (QEMUClock *clock) +void qemu_run_timers (QEMUClock *clock) {QEMUTimer **ptimer_head, *ts;int64_t current_time;
qemu-timer.h +1 -0
@@ -59,6 +59,7 @@ int qemu_timer_pending(QEMUTimer *ts);int qemu_timer_expired (QEMUTimer *timer_head,int64_t current_time);uint64_t qemu_timer_expire_time_ns (QEMUTimer *ts); +void qemu_run_timers (QEMUClock *clock);void qemu_run_all_timers (void );int qemu_alarm_pending (void );void configure_alarms (char const *opt);
qtest.c +45 -0
69 lines not on this page · raw message
Signature · 1 line
1.7.7.1