buildframework/helium/sf/python/pythoncore/lib/pythoncoretests/test_compilation.py
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 588 c7c26511138f
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
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
#===============================================================================
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    19
"""test compilation """
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    20
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 588
diff changeset
    21
# pylint: disable=R0201
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import unittest
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import compilation
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import sysdef.api
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import tempfile
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
from shutil import rmtree
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
_logger = logging.getLogger('test.compilation')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
logging.basicConfig(level=logging.INFO)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
class CompilationTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
    """ Unit test case for compilation.py """
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    36
    def test_read_op_bins_per_unt_empty_logs_lst(self):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
        """ Testing read_output_binaries_per_unit method with empty log list """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
        sysdefpath = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'sysdefs', 'canonical_system_definition.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
        sysDef = sysdef.api.SystemDefinition(sysdefpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
        bsl = compilation.BinarySizeLogger(sysDef)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
        self.assertRaises(Exception, bsl.read_output_binaries_per_unit, "")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
    def test_read_output_binaries_per_unit(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
        """ Testing read_output_binaries_per_unit method """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
        sysdefpath = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'sysdefs', 'canonical_system_definition.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        sysDef = sysdef.api.SystemDefinition(sysdefpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
        bsl = compilation.BinarySizeLogger(sysDef)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
        loglist = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'logs', 'test_build.log')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        bsl.read_output_binaries_per_unit(loglist.split(';'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
        
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    51
    def test_read_bin_sizes_rom_op_empty_logs_lst(self):
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        """ Testing read_binary_sizes_in_rom_output_logs method with empty log list """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
        sysdefpath = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'sysdefs', 'canonical_system_definition.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
        sysDef = sysdef.api.SystemDefinition(sysdefpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        bsl = compilation.BinarySizeLogger(sysDef)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
        self.assertRaises(Exception, bsl.read_binary_sizes_in_rom_output_logs, "")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
    def test_read_binary_sizes_in_rom_output_logs(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        """ Testing read_binary_sizes_in_rom_output_logs method """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
        sysdefpath = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'sysdefs', 'canonical_system_definition.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
        sysDef = sysdef.api.SystemDefinition(sysdefpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        bsl = compilation.BinarySizeLogger(sysDef)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        loglist = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'logs', 'test_build.log')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        bsl.read_output_binaries_per_unit(loglist.split(';'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
        romloglist = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'logs', 'test_rom.log')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        bsl.read_binary_sizes_in_rom_output_logs(romloglist.split(';'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
    def test_write2csvfile(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        """ Testing write2csvfile method """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        sysdefpath = os.path.join(os.environ['TEST_DATA'], 'data', 'compile', 'sysdefs', 'canonical_system_definition.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        sysDef = sysdef.api.SystemDefinition(sysdefpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
        bsl = compilation.BinarySizeLogger(sysDef)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        tmpdir = tempfile.mkdtemp()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        output = os.path.join(tmpdir, 'test_flash_image_size_data.csv')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        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
    76
        bsl.write2csvfile(output, sysdeflist.split(','))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        tempFile = open(output,'r')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        contents = tempFile.readlines()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
        tempFile.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
        rmtree(tmpdir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        assert len(contents) > 0