gendata.py 1.8 KB
Newer Older
C
Cleber Rosa 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#!/usr/bin/python

# This program 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.
#
# This program 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 LICENSE for more details.
#
# Copyright: Red Hat Inc. 2014
# Author: Cleber Rosa <cleber@redhat.com>

import os

from avocado import test
from avocado import job


class gendata(test.Test):

    """
    Simple test that generates data to be persisted after the test is run
    """

    def generate_bsod(self):
        try:
            from PIL import Image
            from PIL import ImageDraw
        except ImportError:
            return

        text = ["DREADED BLUE SCREEN OF DEATH"]
37
        dmesg_path = os.path.join(self.job.logdir, "sysinfo", "pre", "dmesg_-c")
C
Cleber Rosa 已提交
38 39 40 41 42 43 44
        self.log.info("dmesg_path: %s", dmesg_path)
        if os.path.exists(dmesg_path):
            dmesg = open(dmesg_path)
            text = dmesg.readlines()[0:50]

        bsod = Image.new("RGB", (640, 480), "blue")
        draw = ImageDraw.Draw(bsod)
45
        y = 2
C
Cleber Rosa 已提交
46 47 48
        for line in text:
            draw.text((2, y), line)
            y += 12
49
        bsod.save(os.path.join(self.outputdir, "bsod.png"))
C
Cleber Rosa 已提交
50 51 52

    def generate_json(self):
        import json
53
        output_path = os.path.join(self.outputdir, "test.json")
C
Cleber Rosa 已提交
54
        output = {"basedir": self.basedir,
55
                  "outputdir": self.outputdir}
C
Cleber Rosa 已提交
56 57 58 59 60 61 62 63
        json.dump(output, open(output_path, "w"))

    def action(self):
        self.generate_bsod()
        self.generate_json()

if __name__ == "__main__":
    job.main()