buildframework/helium/sf/python/pythoncore/lib/pythoncoretests/test_compilation.py
author wbernard
Tue, 27 Apr 2010 08:33:08 +0300
changeset 587 85df38eb4012
child 588 c7c26511138f
permissions -rw-r--r--
helium_9.0-a7879c935424
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
#============================================================================ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
#Name        : test_compilation.py 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Description:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
import unittest
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
import compilation
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import sysdef.api
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import tempfile
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
from shutil import rmtree
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
_logger = logging.getLogger('test.compilation')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
logging.basicConfig(level=logging.INFO)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
class CompilationTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
    """ Unit test case for compilation.py """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
    def test_read_output_binaries_per_unit_with_empty_logs_list(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
        """ Testing read_output_binaries_per_unit method with empty log list """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
        sysdefpath = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'sysdefs', 'canonical_system_definition.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
        sysDef = sysdef.api.SystemDefinition(sysdefpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
        bsl = compilation.BinarySizeLogger(sysDef)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
        self.assertRaises(Exception, bsl.read_output_binaries_per_unit, "")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
    def test_read_output_binaries_per_unit(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
        """ Testing read_output_binaries_per_unit method """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
        sysdefpath = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'sysdefs', 'canonical_system_definition.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
        sysDef = sysdef.api.SystemDefinition(sysdefpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
        bsl = compilation.BinarySizeLogger(sysDef)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
        loglist = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'logs', 'test_build.log')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        bsl.read_output_binaries_per_unit(loglist.split(';'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
    def test_read_binary_sizes_in_rom_output_logs_with_empty_logs_list(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        """ Testing read_binary_sizes_in_rom_output_logs method with empty log list """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
        sysdefpath = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'sysdefs', 'canonical_system_definition.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
        sysDef = sysdef.api.SystemDefinition(sysdefpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        bsl = compilation.BinarySizeLogger(sysDef)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
        self.assertRaises(Exception, bsl.read_binary_sizes_in_rom_output_logs, "")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
    def test_read_binary_sizes_in_rom_output_logs(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
        """ Testing read_binary_sizes_in_rom_output_logs method """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
        sysdefpath = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'sysdefs', 'canonical_system_definition.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        sysDef = sysdef.api.SystemDefinition(sysdefpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        bsl = compilation.BinarySizeLogger(sysDef)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
        loglist = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'logs', 'test_build.log')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
        bsl.read_output_binaries_per_unit(loglist.split(';'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        romloglist = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'logs', 'test_rom.log')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        bsl.read_binary_sizes_in_rom_output_logs(romloglist.split(';'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
    def test_write2csvfile(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        """ Testing write2csvfile method """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
        sysdefpath = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'sysdefs', 'canonical_system_definition.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
        sysDef = sysdef.api.SystemDefinition(sysdefpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        bsl = compilation.BinarySizeLogger(sysDef)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        tmpdir = tempfile.mkdtemp()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        output = os.path.join(tmpdir, 'test_flash_image_size_data.csv')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
        sysdeflist = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'sysdefs', 'build.sysdef.xml') + ", " + os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'sysdefs', 'layers.sysdef.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        bsl.write2csvfile(output, sysdeflist.split(','))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        tempFile = open(output,'r')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        contents = tempFile.readlines()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        tempFile.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        rmtree(tmpdir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        assert len(contents) > 0