1 | ## @file
|
---|
2 | # Unit tests for TianoCompress utility
|
---|
3 | #
|
---|
4 | # Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>
|
---|
5 | #
|
---|
6 | # SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 | #
|
---|
8 |
|
---|
9 | ##
|
---|
10 | # Import Modules
|
---|
11 | #
|
---|
12 | from __future__ import print_function
|
---|
13 | import os
|
---|
14 | import random
|
---|
15 | import sys
|
---|
16 | import unittest
|
---|
17 |
|
---|
18 | import TestTools
|
---|
19 |
|
---|
20 | class Tests(TestTools.BaseToolsTest):
|
---|
21 |
|
---|
22 | def setUp(self):
|
---|
23 | TestTools.BaseToolsTest.setUp(self)
|
---|
24 | self.toolName = 'TianoCompress'
|
---|
25 |
|
---|
26 | def testHelp(self):
|
---|
27 | result = self.RunTool('--help', logFile='help')
|
---|
28 | #self.DisplayFile('help')
|
---|
29 | self.assertTrue(result == 0)
|
---|
30 |
|
---|
31 | def compressionTestCycle(self, data):
|
---|
32 | path = self.GetTmpFilePath('input')
|
---|
33 | self.WriteTmpFile('input', data)
|
---|
34 | result = self.RunTool(
|
---|
35 | '-e',
|
---|
36 | '-o', self.GetTmpFilePath('output1'),
|
---|
37 | self.GetTmpFilePath('input')
|
---|
38 | )
|
---|
39 | self.assertTrue(result == 0)
|
---|
40 | result = self.RunTool(
|
---|
41 | '-d',
|
---|
42 | '-o', self.GetTmpFilePath('output2'),
|
---|
43 | self.GetTmpFilePath('output1')
|
---|
44 | )
|
---|
45 | self.assertTrue(result == 0)
|
---|
46 | start = self.ReadTmpFile('input')
|
---|
47 | finish = self.ReadTmpFile('output2')
|
---|
48 | startEqualsFinish = start == finish
|
---|
49 | if not startEqualsFinish:
|
---|
50 | print()
|
---|
51 | print('Original data did not match decompress(compress(data))')
|
---|
52 | self.DisplayBinaryData('original data', start)
|
---|
53 | self.DisplayBinaryData('after compression', self.ReadTmpFile('output1'))
|
---|
54 | self.DisplayBinaryData('after decompression', finish)
|
---|
55 | self.assertTrue(startEqualsFinish)
|
---|
56 |
|
---|
57 | def testRandomDataCycles(self):
|
---|
58 | for i in range(8):
|
---|
59 | data = self.GetRandomString(1024, 2048)
|
---|
60 | self.compressionTestCycle(data)
|
---|
61 | self.CleanUpTmpDir()
|
---|
62 |
|
---|
63 | TheTestSuite = TestTools.MakeTheTestSuite(locals())
|
---|
64 |
|
---|
65 | if __name__ == '__main__':
|
---|
66 | allTests = TheTestSuite()
|
---|
67 | unittest.TextTestRunner().run(allTests)
|
---|
68 |
|
---|
69 |
|
---|