2 # vim: ai ts=4 sts=4 et sw=4
4 # Copyright (c) 2007 Intel Corporation
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the Free
8 # Software Foundation; version 2 of the License
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc., 59
17 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 import os
, re
, shutil
, sys
, tempfile
, unittest
21 sys
.path
.insert(0, '/usr/share/pdk/lib')
25 class TestPlatform(unittest
.TestCase
):
27 self
.workdir
= tempfile
.mkdtemp()
28 self
.platform_name
= 'unittest_platform'
29 self
.platform_root
= os
.path
.join(self
.workdir
, 'platforms')
30 self
.repo_filename
= 'unittest.repo'
31 createSamplePlatform(self
.platform_root
, self
.platform_name
, self
.repo_filename
)
33 if os
.path
.isdir(self
.workdir
):
34 shutil
.rmtree(self
.workdir
)
35 def test001Instantiate(self
):
36 """Simple instantiation test"""
37 platform
= Platform
.Platform(self
.workdir
, self
.platform_name
)
38 def testStrRepr(self
):
39 """Test __str__ and __repr__ functions"""
40 platform
= Platform
.Platform(self
.workdir
, self
.platform_name
)
41 temp
= platform
.__str
__()
42 temp
= platform
.__repr
__()
44 """Test storing and retrieving values"""
45 platform
= Platform
.Platform(self
.workdir
, self
.platform_name
)
46 # Make sure it is storing what we passed in
47 self
.assertEqual(platform
.sdk_path
, self
.workdir
)
48 self
.assertEqual(platform
.name
, self
.platform_name
)
49 def testRepoFiles(self
):
50 """Test correctness of repository files"""
51 platform
= Platform
.Platform(self
.workdir
, self
.platform_name
)
53 def createSamplePlatformDir(platform_root
, platform_name
, repo_filename
= "unittest.repo"):
54 platform_dir
= os
.path
.join(platform_root
, platform_name
)
55 os
.makedirs(platform_dir
)
56 for dirname
in ('buildroot_repos', 'fsets', 'target_repos'):
57 os
.mkdir(os
.path
.join(platform_dir
, dirname
))
58 cmdfile
=open(os
.path
.join(platform_dir
,'usb_kernel_cmdline'),'w')
60 cmdfile
=open(os
.path
.join(platform_dir
,'hd_kernel_cmdline'),'w')
62 test_fsets
.createSampleFsetFile(os
.path
.join(platform_dir
, 'fsets', 'unittest.fset'))
63 createSampleJailrootPackages(os
.path
.join(platform_dir
, 'buildroot.packages'))
64 createSampleJailrootExtras(os
.path
.join(platform_dir
, 'buildroot_extras'))
65 createSamplePlatformConfigFile(platform_name
, os
.path
.join(platform_root
, "platforms.cfg"))
67 def createSampleJailrootPackages(filename
):
69 # stuff needed for building pretty much any package
70 tar patch gcc gcc-c++ make automake autoconf libtool file rpm-build bzip2
72 # not really needed for building, but it sure makes life easier
73 vim-enhanced tree less diffutils yum
75 # stuff needed for kernel development
76 module-init-tools ncurses-devel nash
78 # Packages required for making bootable images
79 syslinux busybox squashfs-tools
81 text2file(filename
, contents
)
83 def createSampleJailrootExtras(filename
):
85 squashfs-tools busybox-initramfs dosfstools
86 syslinux module-init-tools mtools gpgv
88 text2file(filename
, contents
)
90 def createSamplePlatformConfigFile(platform_name
, filename
):
93 description = Unittest Platform
95 target_os = ubuntu""" % platform_name
96 text2file(filename
, contents
)
98 def text2file(filename
, text
):
99 out_file
= open(filename
, 'w')
100 print >> out_file
, text
103 if __name__
== '__main__':
104 if len(sys
.argv
) == 2 and sys
.argv
[1] == "-v":
105 suite
= unittest
.TestLoader().loadTestsFromTestCase(TestPlatform
)
106 unittest
.TextTestRunner(verbosity
=2).run(suite
)