1
# Copyright (C) 2010, 2011, 2012 Linaro
3
# Author: Milo Casagrande <milo.casagrande@linaro.org>
5
# This file is part of Linaro Image Tools.
7
# Linaro Image Tools is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License
9
# as published by the Free Software Foundation; either version 2
10
# of the License, or (at your option) any later version.
12
# Linaro Image Tools is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with Linaro Image Tools; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23
from linaro_image_tools.testing import TestCaseWithFixtures
24
from linaro_image_tools.tests.fixtures import (
26
CreateTempFileFixture,
29
from linaro_image_tools.hwpack.hwpack_convert import (
31
HwpackConverterException,
32
check_and_validate_args,
37
"""Defines the args for the command line options."""
38
def __init__(self, input_file, output_file=None):
39
self.CONFIG_FILE = input_file
40
self.out = output_file
43
class HwpackConverterTests(TestCaseWithFixtures):
44
"""Test class for the hwpack converter."""
47
super(HwpackConverterTests, self).setUp()
49
def test_wrong_input_file(self):
50
"""Pass a non-existing file."""
51
input_file = '/tmp/foobaz'
53
HwpackConverterException, check_and_validate_args,
54
Args(input_file=input_file))
56
def test_wrong_input_dir(self):
57
"""Pass a directory instead of file."""
58
temp_file = tempfile.NamedTemporaryFile()
59
temp_dir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
61
HwpackConverterException, check_and_validate_args,
62
Args(input_file=temp_file.name, output_file=temp_dir))
64
def test_same_input_output_file(self):
65
"""Pass the same existing file path to the two arguments."""
66
temp_file = self.useFixture(CreateTempFileFixture()).get_file_name()
68
HwpackConverterException, check_and_validate_args,
69
Args(input_file=temp_file, output_file=temp_file))
71
def test_basic_parse(self):
72
ini_format = '[hwpack]\nformat=2.0\nsupport=supported'
73
output_format = "format: '3.0'\nsupport: supported\n"
74
input_file = self.useFixture(CreateTempFileFixture(ini_format)).\
76
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
77
converter = HwpackConverter(input_file, output_file)
79
self.assertEqual(output_format, str(converter))
81
def test_architectures_section_creation(self):
82
"""Tests that we create the correct architectures list in the
85
ini_format = '[hwpack]\nformat=2.0\narchitectures=armhf armel'
86
output_format = "format: '3.0'\narchitectures:\n- armhf\n- armel\n"
87
input_file = self.useFixture(CreateTempFileFixture(ini_format)).\
89
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
90
converter = HwpackConverter(input_file, output_file)
92
self.assertEqual(output_format, str(converter))
94
def test_bootloaders(self):
95
"""Tests the correct creation of the bootloaders part."""
96
ini_format = ("[hwpack]\nformat=2.0\nu_boot_package=a_package\n"
97
"u_boot_file=a_file\nu_boot_in_boot_part=Yes\n"
99
out_format = ("format: '3.0'\nbootloaders:\n u_boot:\n dd: '33'"
100
"\n file: a_file\n in_boot_part: true\n"
101
" package: a_package\n")
102
input_file = self.useFixture(CreateTempFileFixture(ini_format)).\
104
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
105
converter = HwpackConverter(input_file, output_file)
107
self.assertEqual(out_format, str(converter))
109
def test_extra_boot_options(self):
110
"""Tests the correct creation of the extra_boot_options part."""
111
ini_format = ("[hwpack]\nformat=2.0\nu_boot_package=a_package\n"
112
"extra_boot_options=opt1 opt2")
113
out_format = ("format: '3.0'\nbootloaders:\n u_boot:\n "
114
" extra_boot_options:\n - opt1\n "
115
"- opt2\n package: a_package\n")
116
input_file = self.useFixture(CreateTempFileFixture(ini_format)).\
118
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
119
converter = HwpackConverter(input_file, output_file)
121
self.assertEqual(out_format, str(converter))
123
def test_extra_serial_options(self):
124
"""Tests the correct creation of the extra_serial_options part."""
125
ini_format = ("[hwpack]\nformat=2.0\nextra_serial_options=opt1 opt2")
126
out_format = ("format: '3.0'\nextra_serial_options:\n- opt1\n- opt2\n")
127
input_file = self.useFixture(CreateTempFileFixture(ini_format)).\
129
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
130
converter = HwpackConverter(input_file, output_file)
132
self.assertEqual(out_format, str(converter))