import unittest
import os
import logging
import re
import shutil
import tempfile
import glob
import oeqa.utils.ftools as ftools
from oeqa.selftest.base import oeSelfTest
from oeqa.utils.commands import runCmd, bitbake, get_bb_var, create_temp_layer, runqemu
from oeqa.utils.decorators import testcase
class DevtoolBase(oeSelfTest):
def _test_recipe_contents(self, recipefile, checkvars, checkinherits):
with open(recipefile, 'r') as f:
invar = None
invalue = None
for line in f:
var = None
if invar:
value = line.strip().strip('"')
if value.endswith('\\'):
invalue += ' ' + value[:-1].strip()
continue
else:
invalue += ' ' + value.strip()
var = invar
value = invalue
invar = None
elif '=' in line:
splitline = line.split('=', 1)
var = splitline[0].rstrip()
value = splitline[1].strip().strip('"')
if value.endswith('\\'):
invalue = value[:-1].strip()
invar = var
continue
elif line.startswith('inherit '):
inherits = line.split()[1:]
if var and var in checkvars:
needvalue = checkvars.pop(var)
if needvalue is None:
self.fail('Variable %s should not appear in recipe')
if isinstance(needvalue, set):
value = set(value.split())
self.assertEqual(value, needvalue, 'values for %s do not match' % var)
missingvars = {}
for var, value in checkvars.iteritems():
if value is not None:
missingvars[var] = value
self.assertEqual(missingvars, {}, 'Some expected variables not found in recipe: %s' % checkvars)
for inherit in checkinherits:
self.assertIn(inherit, inherits, 'Missing inherit of %s' % inherit)
def _check_bbappend(self, testrecipe, recipefile, appenddir):
result = runCmd('bitbake-layers show-appends', cwd=self.builddir)
resultlines = result.output.splitlines()
inrecipe = False
bbappends = []
bbappendfile = None
for line in resultlines:
if inrecipe:
if line.startswith(' '):
bbappends.append(line.strip())
else:
break
elif line == '%s:' % os.path.basename(recipefile):
inrecipe = True
self.assertLessEqual(len(bbappends), 2, '%s recipe is being bbappended by another layer - bbappends found:\n %s' % (testrecipe, '\n '.join(bbappends)))
for bbappend in bbappends:
if bbappend.startswith(appenddir):
bbappendfile = bbappend
break
else:
self.fail('bbappend for recipe %s does not seem to be created in test layer' % testrecipe)
return bbappendfile
def _create_temp_layer(self, templayerdir, addlayer, templayername, priority=999, recipepathspec='recipes-*/*'):
create_temp_layer(templayerdir, templayername, priority, recipepathspec)
if addlayer:
self.add_command_to_tearDown('bitbake-layers remove-layer %s || true' % templayerdir)
result = runCmd('bitbake-layers add-layer %s' % templayerdir, cwd=self.builddir)
def _process_ls_output(self, output):
"""
Convert ls -l output to a format we can reasonably compare from one context
to another (e.g. from host to target)
"""
filelist = []
for line in output.splitlines():
splitline = line.split()
if len(splitline) < 8:
self.fail('_process_ls_output: invalid output line: %s' % line)
# Remove trailing . on perms
splitline[0] = splitline[0].rstrip('.')
# Remove leading . on paths
splitline[-1] = splitline[-1].lstrip('.')
# Drop fields we don't want to compare
del splitline[7]
del splitline[6]
del splitline[5]
del splitline[4]
del splitline[1]
filelist.append(' '.join(splitline))
return filelist
class DevtoolTests(DevtoolBase):
def setUp(self):
"""Test case setup function"""
super(DevtoolTests, self).setUp()
self.workspacedir = os.path.join(self.builddir, 'workspace')
self.assertTrue(not os.path.exists(self.workspacedir),
'This test cannot be run with a workspace directory '
'under the build directory')
def _check_src_repo(self, repo_dir):
"""Check srctree git repository"""
self.assertTrue(os.path.isdir(os.path.join(repo_dir, '.git')),
'git repository for external source tree not found')
result = runCmd('git status --porcelain', cwd=repo_dir)
self.assertEqual(result.output.strip(), "",
'Created git repo is not clean')
result = runCmd('git symbolic-ref HEAD', cwd=repo_dir
|