Skip to contentSkip to conversation

lib/oeqa/runtime: add test for gzip

PATCH In review [email protected] 2 participants 4 messages Jan 9, 2014 – Jan 20, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/oeqa/runtime: add test for gzip

From: Ting Wang <[email protected]>

Function tests:
1)gzip compress file
2)compressed file integrity check
3)zcat compress file
4)gzip decompress file

---
 meta/classes/testimage.bbclass |    4 ++--
 meta/lib/oeqa/runtime/gzip.py  |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 meta/lib/oeqa/runtime/gzip.py
meta/classes/testimage.bbclass +2 -2
index 4777e14..0d861e6 100644
@@ -27,8 +27,8 @@ TEST_LOG_DIR ?= "${WORKDIR}/testimage"
 
 DEFAULT_TEST_SUITES = "ping auto"
 DEFAULT_TEST_SUITES_pn-core-image-minimal = "ping"
-DEFAULT_TEST_SUITES_pn-core-image-sato = "ping ssh df connman syslog xorg scp vnc date rpm smart dmesg python"
-DEFAULT_TEST_SUITES_pn-core-image-sato-sdk = "ping ssh df connman syslog xorg scp vnc date perl ldd gcc rpm smart kernelmodule dmesg python"
+DEFAULT_TEST_SUITES_pn-core-image-sato = "ping ssh df connman syslog xorg scp vnc date rpm smart dmesg python gzip"
+DEFAULT_TEST_SUITES_pn-core-image-sato-sdk = "ping ssh df connman syslog xorg scp vnc date perl ldd gcc rpm smart kernelmodule dmesg python gzip"
 
 TEST_SUITES ?= "${DEFAULT_TEST_SUITES}"
 
meta/lib/oeqa/runtime/gzip.py new file +32 -0
new file mode 100644
index 0000000..50e3b8f
@@ -0,0 +1,32 @@
+import unittest
+import os
+from oeqa.oetest import oeRuntimeTest, skipModule
+from oeqa.utils.decorators import *
+
+class GzipFunctionTest(oeRuntimeTest):
+
+    @skipUnlessPassed('test_ssh')
+    def test_gzip_create_testfile(self):
+        (status, output) = self.target.run('echo It is a test file > /tmp/testfile.gzip')
+        self.assertEqual(status, 0, msg="gzip test file create failed")
+
+    @skipUnlessPassed('test_gzip_create_testfile')
+    def test_gzip_fun1_compress(self):
+        (status, output) = self.target.run('gzip /tmp/testfile.gzip')
+        self.assertEqual(status, 0, msg="gzip compress file failed.")
+
+    def test_gzip_fun2_integrity_check(self):
+        (status, output) = self.target.run('gzip -t /tmp/testfile.gzip.gz')
+        self.assertEqual(status, 0, msg="Check the compressed file integrity failed")
+
+    def test_gzip_fun3_zcat(self):
+        (status, output) = self.target.run('zcat /tmp/testfile.gzip.gz')
+        self.assertEqual(output, "It is a test file", msg="Incorrect output: %s" % output)
+
+    def test_gzip_fun4_decompress(self):
+        (status, output) = self.target.run('gunzip /tmp/testfile.gzip.gz && ls /tmp/testfile.gzip')
+        self.assertEqual(status, 0, msg="gzip decompress file failed.")
+
+    @classmethod
+    def tearDownClass(self):
+        oeRuntimeTest.tc.target.run("rm /tmp/testfile.gzip")
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 5 lines · On 9 January 2014 08:25, <[email protected]> wrote:

Function tests:
1)gzip compress file
2)compressed file integrity check
3)zcat compress file
4)gzip decompress file

Wouldn't this be better implemented as a ptest for gzip? The qemu image tests are more concerned with image-wide functionality that can't be unit tested independently, but verifying that gzip works can be.

Also, your test simply verifies that the commands execute, not that the contents is what you expect: a gzip that produced corrupted archives wouldn't be detected by this test.

Finally, as I learnt yesterday, the skipUnlessPassed decorator isn't used to enforce ordering, so test_gzip_fun1_compress only runs after _create_testfile because it sorts that way alphabetically, not because of your decorators. As creating a file isn't a test, just do that in the test itself.

Ross

author
#2 lore raw
In reply to [email protected]

Any issues about this case ?

Thanks
Ting

Quoted 67 lines · [email protected] wrote:

From: Ting Wang <[email protected]>

Function tests:
1)gzip compress file
2)compressed file integrity check
3)zcat compress file
4)gzip decompress file

---
 meta/classes/testimage.bbclass |    4 ++--
 meta/lib/oeqa/runtime/gzip.py  |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 meta/lib/oeqa/runtime/gzip.py
meta/classes/testimage.bbclass +2 -2
index 4777e14..0d861e6 100644
@@ -27,8 +27,8 @@ TEST_LOG_DIR ?= "${WORKDIR}/testimage"
 
 DEFAULT_TEST_SUITES = "ping auto"
 DEFAULT_TEST_SUITES_pn-core-image-minimal = "ping"
-DEFAULT_TEST_SUITES_pn-core-image-sato = "ping ssh df connman syslog xorg scp vnc date rpm smart dmesg python"
-DEFAULT_TEST_SUITES_pn-core-image-sato-sdk = "ping ssh df connman syslog xorg scp vnc date perl ldd gcc rpm smart kernelmodule dmesg python"
+DEFAULT_TEST_SUITES_pn-core-image-sato = "ping ssh df connman syslog xorg scp vnc date rpm smart dmesg python gzip"
+DEFAULT_TEST_SUITES_pn-core-image-sato-sdk = "ping ssh df connman syslog xorg scp vnc date perl ldd gcc rpm smart kernelmodule dmesg python gzip"
 
 TEST_SUITES ?= "${DEFAULT_TEST_SUITES}"
 
meta/lib/oeqa/runtime/gzip.py new file +32 -0
new file mode 100644
index 0000000..50e3b8f
@@ -0,0 +1,32 @@
+import unittest
+import os
+from oeqa.oetest import oeRuntimeTest, skipModule
+from oeqa.utils.decorators import *
+
+class GzipFunctionTest(oeRuntimeTest):
+
+    @skipUnlessPassed('test_ssh')
+    def test_gzip_create_testfile(self):
+        (status, output) = self.target.run('echo It is a test file > /tmp/testfile.gzip')
+        self.assertEqual(status, 0, msg="gzip test file create failed")
+
+    @skipUnlessPassed('test_gzip_create_testfile')
+    def test_gzip_fun1_compress(self):
+        (status, output) = self.target.run('gzip /tmp/testfile.gzip')
+        self.assertEqual(status, 0, msg="gzip compress file failed.")
+
+    def test_gzip_fun2_integrity_check(self):
+        (status, output) = self.target.run('gzip -t /tmp/testfile.gzip.gz')
+        self.assertEqual(status, 0, msg="Check the compressed file integrity failed")
+
+    def test_gzip_fun3_zcat(self):
+        (status, output) = self.target.run('zcat /tmp/testfile.gzip.gz')
+        self.assertEqual(output, "It is a test file", msg="Incorrect output: %s" % output)
+
+    def test_gzip_fun4_decompress(self):
+        (status, output) = self.target.run('gunzip /tmp/testfile.gzip.gz && ls /tmp/testfile.gzip')
+        self.assertEqual(status, 0, msg="gzip decompress file failed.")
+
+    @classmethod
+    def tearDownClass(self):
+        oeRuntimeTest.tc.target.run("rm /tmp/testfile.gzip")
#3 lore raw
Quoted 1 line · wangting

Any issues about this case ?

Everything I said in my reply on 9th January. I think it should be a ptest instead, and it doesn't actually check that gzip is working correctly.

Ross