Skip to contentSkip to conversation

testimage: Run commands in target and host when test fails

PATCH Superseded [email protected] 2 participants 4 messages Aug 17, 2015 – Aug 18, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 testimage: Run commands in target and host when test fails

From: Mariano Lopez <[email protected]>

This patch modify three files altought two of them are minimal modifications:

testimage.bbclass:
Create new vars for easy modification of the dump
directory and commands to be run on host and target when a test fails
TESTIMAGE_DUMP_DIR: Directory to save the dumps
TESTIMAGE_DUMP_TRG: Commands to run on target
TESTIMAGE_DUMP_HST: Commands to run on host

targetcontrol.py:
Extract vars from the datastore for later use

oetest.py:
- Allow to use the vars defined in testimage class
- Now able to run commands in the host and dump the results
- Fix an issue with the condition where to run the dump commands (Before it run the commands every test after a failure, now it runs the commands only in tests that failed)
- Fix the output to stdout

[YOCTO #8118]

---
 meta/classes/testimage.bbclass |  9 +++++++++
 meta/lib/oeqa/oetest.py        | 42 +++++++++++++++++++++++++++---------------
 meta/lib/oeqa/targetcontrol.py |  3 +++
 3 files changed, 39 insertions(+), 15 deletions(-)
meta/classes/testimage.bbclass +9 -0
index 140babe..1580a4e 100644
@@ -56,6 +56,15 @@ TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:d
 TESTIMAGELOCK = "${TMPDIR}/testimage.lock"
 TESTIMAGELOCK_qemuall = ""
 
+TESTIMAGE_DUMP_DIR ?= "/tmp/oe-saved-tests/"
+
+python () {
+    target_cmds = ["top -bn1", "ps", "free", "df", "_ping", "dmesg", "netstat -an", "ip address", "_logs"]
+    host_cmds = ["top -bn1", "ps", "free", "df", "memstat", "dmesg", "netstat -an"]
+    d.setVar("TESTIMAGE_DUMP_TRG", target_cmds)
+    d.setVar("TESTIMAGE_DUMP_HST", host_cmds)
+}
+
 python do_testimage() {
     testimage_main(d)
 }
meta/lib/oeqa/oetest.py +27 -15

70 lines not on this page · raw message

meta/lib/oeqa/targetcontrol.py +3 -0
index c76887b..7589ea4 100644
@@ -123,6 +123,9 @@ class QemuTarget(BaseTarget):
         self.origrootfs = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True),  d.getVar("IMAGE_LINK_NAME", True) + '.' + self.image_fstype)
         self.rootfs = os.path.join(self.testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.' + self.image_fstype)
         self.kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("KERNEL_IMAGETYPE", False) + '-' + d.getVar('MACHINE', False) + '.bin')
+        self.dump_trg = d.getVar("TESTIMAGE_DUMP_TRG", False)
+        self.dump_hst = d.getVar("TESTIMAGE_DUMP_HST", False)
+        self.dump_dir = d.getVar("TESTIMAGE_DUMP_DIR", False)
 
         # Log QemuRunner log output to a file
         import oe.path
Signature · 1 line
1.8.4.5
#1 lore raw

Hi Mariano,

Quoted 5 lines · On Monday 17 August 2015 12:41:42 [email protected] wrote:

From: Mariano Lopez <[email protected]>

This patch modify three files altought two of them are minimal modifications:

Quoted 7 lines

testimage.bbclass:
Create new vars for easy modification of the dump
directory and commands to be run on host and target when a test fails
TESTIMAGE_DUMP_DIR: Directory to save the dumps
TESTIMAGE_DUMP_TRG: Commands to run on target
TESTIMAGE_DUMP_HST: Commands to run on host

Can we please use full names (i.e. "...HOST" and "...TARGET")? We're not short of space here ;)

Quoted 39 lines

targetcontrol.py:
Extract vars from the datastore for later use

oetest.py:
- Allow to use the vars defined in testimage class
- Now able to run commands in the host and dump the results
- Fix an issue with the condition where to run the dump commands (Before it run the commands every test after a failure, now it runs the commands only in tests that failed)
- Fix the output to stdout

[YOCTO #8118]

---
 meta/classes/testimage.bbclass |  9 +++++++++
 meta/lib/oeqa/oetest.py        | 42
+++++++++++++++++++++++++++--------------- meta/lib/oeqa/targetcontrol.py |
 3 +++
 3 files changed, 39 insertions(+), 15 deletions(-)
meta/classes/testimage.bbclass +0 -0
index 140babe..1580a4e 100644
@@ -56,6 +56,15 @@ TESTIMAGEDEPENDS_qemuall =

"qemu-native:do_populate_sysroot qemu-helper-native:d TESTIMAGELOCK = "${TMPDIR}/testimage.lock"
TESTIMAGELOCK_qemuall = ""

meta/classes/testimage.bbclass +4 -0
+TESTIMAGE_DUMP_DIR ?= "/tmp/oe-saved-tests/"
+
+python () {
+    target_cmds = ["top -bn1", "ps", "free", "df", "_ping", "dmesg",

"netstat -an", "ip address", "_logs"] + host_cmds = ["top -bn1", "ps",
"free", "df", "memstat", "dmesg", "netstat -an"] + d.setVar("TESTIMAGE_DUMP_TRG", target_cmds)

meta/classes/testimage.bbclass TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:d · line 66

Quoted 2 lines
meta/classes/testimage.bbclass +2 -0
+    d.setVar("TESTIMAGE_DUMP_HST", host_cmds)
+}

This is isn't how I would recommend doing this. What I suggested earlier when we talked about this was:

testimage_dump_target() {
	top -bn1
	ps
	free
	df
	...
}

Then you'd just d.getVar('testimage_dump_target', True), and treat the contents as a complete shell script to be run - i.e. write it to a file with #!/bin/sh as a prefix and run it. As a bonus, the value can be overridden or appended to from elsewhere. (This is similar to how we deal with pkg_postinst_<packagename> for postinstall scripts.)

meta/classes/testimage.bbclass

Quoted 3 lines
meta/classes/testimage.bbclass +3 -0
+        self.dump_trg = d.getVar("TESTIMAGE_DUMP_TRG", False)
+        self.dump_hst = d.getVar("TESTIMAGE_DUMP_HST", False)
+        self.dump_dir = d.getVar("TESTIMAGE_DUMP_DIR", False)

As a general note - for this kind of thing, you need to be specifying True not False for the expansion parameter - the value may well contain references or other expressions (such as ${TMPDIR}) that need expanding. In fact, it's relatively uncommon for False to be what you want - most of the time the value should be expanded if you're about to use it for something.

Cheers,
Paul

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre
#2 lore raw

Hi Paul,

Quoted 15 lines · Paul Eggleton

Hi Mariano,

Quoted 5 lines · On Monday 17 August 2015 12:41:42 [email protected] wrote:

From: Mariano Lopez <[email protected]>

This patch modify three files altought two of them are minimal modifications:

Quoted 7 lines

testimage.bbclass:
Create new vars for easy modification of the dump
directory and commands to be run on host and target when a test fails
TESTIMAGE_DUMP_DIR: Directory to save the dumps
TESTIMAGE_DUMP_TRG: Commands to run on target
TESTIMAGE_DUMP_HST: Commands to run on host

Quoted 2 lines

Can we please use full names (i.e. "...HOST" and "...TARGET")? We're not short of space here ;)

Sure, no problem

Quoted 53 lines
Quoted 40 lines

targetcontrol.py:
Extract vars from the datastore for later use

oetest.py:
- Allow to use the vars defined in testimage class
- Now able to run commands in the host and dump the results
- Fix an issue with the condition where to run the dump commands (Before it run the commands every test after a failure, now it runs the commands only in tests that failed)
- Fix the output to stdout

[YOCTO #8118]

---
  meta/classes/testimage.bbclass |  9 +++++++++
  meta/lib/oeqa/oetest.py        | 42
+++++++++++++++++++++++++++--------------- meta/lib/oeqa/targetcontrol.py |
  3 +++
  3 files changed, 39 insertions(+), 15 deletions(-)
meta/classes/testimage.bbclass +0 -0
index 140babe..1580a4e 100644
@@ -56,6 +56,15 @@ TESTIMAGEDEPENDS_qemuall =

"qemu-native:do_populate_sysroot qemu-helper-native:d TESTIMAGELOCK = "${TMPDIR}/testimage.lock"
TESTIMAGELOCK_qemuall = ""

meta/classes/testimage.bbclass +4 -0
+TESTIMAGE_DUMP_DIR ?= "/tmp/oe-saved-tests/"
+
+python () {
+    target_cmds = ["top -bn1", "ps", "free", "df", "_ping", "dmesg",

"netstat -an", "ip address", "_logs"] + host_cmds = ["top -bn1", "ps",
"free", "df", "memstat", "dmesg", "netstat -an"] + d.setVar("TESTIMAGE_DUMP_TRG", target_cmds)

meta/classes/testimage.bbclass TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:d · line 66

Quoted 2 lines
meta/classes/testimage.bbclass +2 -0
+    d.setVar("TESTIMAGE_DUMP_HST", host_cmds)
+}

This is isn't how I would recommend doing this. What I suggested earlier when we talked about this was:

testimage_dump_target() {
	top -bn1
	ps
	free
	df
	...
}
Quoted 5 lines

Then you'd just d.getVar('testimage_dump_target', True), and treat the contents as a complete shell script to be run - i.e. write it to a file with #!/bin/sh as a prefix and run it. As a bonus, the value can be overridden or appended to from elsewhere. (This is similar to how we deal with pkg_postinst_<packagename> for postinstall scripts.)

Implement this for the host wouldn't be a problem, it gets interesting for the target.These commands would be run from
the serial console, when the network fails, so it would be
difficult to run as a shell script. And also would be difficult to install the scripts on the image because testimage would run after do_rootfs takes place.

What would be the best approach for the target case?

Quoted 8 lines

meta/classes/testimage.bbclass

Quoted 3 lines
meta/classes/testimage.bbclass +3 -0
+        self.dump_trg = d.getVar("TESTIMAGE_DUMP_TRG", False)
+        self.dump_hst = d.getVar("TESTIMAGE_DUMP_HST", False)
+        self.dump_dir = d.getVar("TESTIMAGE_DUMP_DIR", False)

As a general note - for this kind of thing, you need to be specifying True not False for the expansion parameter - the value may well contain references or other expressions (such as ${TMPDIR}) that need expanding. In fact, it's relatively uncommon for False to be what you want - most of the time the value should be expanded if you're about to use it for something.

You are right, I will change that.

Quoted 4 lines

Cheers,
Paul

Signature · 1 line
Mariano Lopez
#3 lore raw
Quoted 93 lines · On Tuesday 18 August 2015 10:18:11 Mariano Lopez wrote:
Quoted 12 lines · Paul Eggleton
Quoted 11 lines · On Monday 17 August 2015 12:41:42 [email protected] wrote:

From: Mariano Lopez <[email protected]>

This patch modify three files altought two of them are minimal modifications:

testimage.bbclass:
Create new vars for easy modification of the dump

directory and commands to be run on host and target when a test fails

Quoted 6 lines
Quoted 3 lines

TESTIMAGE_DUMP_DIR: Directory to save the dumps
TESTIMAGE_DUMP_TRG: Commands to run on target
TESTIMAGE_DUMP_HST: Commands to run on host

Can we please use full names (i.e. "...HOST" and "...TARGET")? We're not short of space here ;)

Sure, no problem

Quoted 62 lines
Quoted 48 lines

targetcontrol.py:
Extract vars from the datastore for later use

oetest.py:
- Allow to use the vars defined in testimage class
- Now able to run commands in the host and dump the

results

- Fix an issue with the condition where to run the

dump commands (Before it run the commands every test after a failure, now it runs the commands only in tests that failed)

- Fix the output to stdout

[YOCTO #8118]

---

  meta/classes/testimage.bbclass |  9 +++++++++
  meta/lib/oeqa/oetest.py        | 42

+++++++++++++++++++++++++++--------------- meta/lib/oeqa/targetcontrol.py |

3 +++

  3 files changed, 39 insertions(+), 15 deletions(-)
(quoted diff) +0 -0

b/meta/classes/testimage.bbclass index 140babe..1580a4e 100644

meta/classes/testimage.bbclass +0 -0
@@ -56,6 +56,15 @@ TESTIMAGEDEPENDS_qemuall =

"qemu-native:do_populate_sysroot qemu-helper-native:d TESTIMAGELOCK = "${TMPDIR}/testimage.lock"

TESTIMAGELOCK_qemuall = ""

meta/classes/testimage.bbclass +4 -0
+TESTIMAGE_DUMP_DIR ?= "/tmp/oe-saved-tests/"
+
+python () {
+    target_cmds = ["top -bn1", "ps", "free", "df", "_ping", "dmesg",

"netstat -an", "ip address", "_logs"] + host_cmds = ["top -bn1", "ps",
"free", "df", "memstat", "dmesg", "netstat -an"] + d.setVar("TESTIMAGE_DUMP_TRG", target_cmds)

meta/classes/testimage.bbclass TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:d · line 66

Quoted 2 lines
meta/classes/testimage.bbclass +2 -0
+    d.setVar("TESTIMAGE_DUMP_HST", host_cmds)
+}

This is isn't how I would recommend doing this. What I suggested earlier when we talked about this was:

testimage_dump_target() {

	top -bn1
	ps
	free
	df
	...
Quoted 8 lines

}

Then you'd just d.getVar('testimage_dump_target', True), and treat the contents as a complete shell script to be run - i.e. write it to a file with #!/bin/sh as a prefix and run it. As a bonus, the value can be overridden or appended to from elsewhere. (This is similar to how we deal with
pkg_postinst_<packagename> for postinstall scripts.)

Quoted 8 lines

Implement this for the host wouldn't be a problem, it gets interesting for the target.These commands would be run from
the serial console, when the network fails, so it would be
difficult to run as a shell script. And also would be difficult to install the scripts on the image because testimage would run after do_rootfs takes place.

What would be the best approach for the target case?

Alright, in that case just split it on newline and send each command one by one.

Cheers,
Paul

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre