Exemple #1
0
 def test_postInstall_topLevel(self):
     test_dir = util.writeTestFiles({})
     self.runCheckCommand(['--target', util.nativeTarget(), 'install', 'test-post-install'], test_dir)
     output = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], os.path.join(test_dir, 'test-post-install'))
     self.assertIn('post-install generated file compiled', output)
     self.assertIn('post-install generated header file included', output)
     self.assertIn('generated .cmake file included', output)
Exemple #2
0
    def test_buildInfo(self):
        test_dir = util.writeTestFiles(Test_Build_Info, True)
        # commit all the test files to git so that the VCS build info gets
        # defined:
        # (set up the git user env vars so we can run git commit without barfing)
        util.setupGitUser()
        subprocess.check_call(['git', 'init', '-q'], cwd=test_dir)
        subprocess.check_call(['git', 'add', '.'], cwd=test_dir)
        subprocess.check_call(
            ['git', 'commit', '-m', 'test build info automated commit', '-q'],
            cwd=test_dir)

        self.runCheckCommand(
            ['--target', util.nativeTarget(), 'build'], test_dir)

        build_time = datetime.datetime.utcnow()
        output = subprocess.check_output([
            './build/' + util.nativeTarget().split(',')[0] +
            '/source/test-trivial-exe'
        ],
                                         cwd=test_dir).decode()
        self.assertIn('vcs clean: 1', output)

        # check build timestamp
        self.assertIn('build timestamp: ', output)
        build_timestamp_s = re.search('build timestamp: (.*)\n', output)
        self.assertTrue(build_timestamp_s)
        build_timestamp_s = build_timestamp_s.group(1)
        build_time_parsed = datetime.datetime.strptime(build_timestamp_s,
                                                       '%Y-%m-%d-%H-%M-%S')
        build_time_skew = build_time_parsed - build_time
        self.assertTrue(abs(build_time_skew.total_seconds()) < 3)
Exemple #3
0
 def test_postInstall_topLevel(self):
     test_dir = util.writeTestFiles({})
     self.runCheckCommand(
         ['--target',
          util.nativeTarget(), 'install', 'test-post-install'], test_dir)
     output = self.runCheckCommand(
         ['--target', util.nativeTarget(), 'build'],
         os.path.join(test_dir, 'test-post-install'))
     self.assertIn('post-install generated file compiled', output)
     self.assertIn('post-install generated header file included', output)
     self.assertIn('generated .cmake file included', output)
Exemple #4
0
 def test_Defines_Application(self):
     test_dir = util.writeTestFiles(Test_Defines_Application)
     stdout = self.runCheckCommand(
         ['--target', util.nativeTarget(), 'build'], test_dir)
     output = subprocess.check_output([
         './build/' + util.nativeTarget().split(',')[0] +
         '/source/test-defines-app'
     ],
                                      cwd=test_dir).decode()
     self.assertIn("1234 yotta", output)
     util.rmRf(test_dir)
Exemple #5
0
 def test_buildTests(self):
     test_dir = util.writeTestFiles(Test_Tests, True)
     stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
     stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'test'], test_dir)
     self.assertIn('test-a', stdout)
     self.assertIn('test-c', stdout)
     self.assertIn('test-d', stdout)
     self.assertIn('test-e', stdout)
     self.assertIn('test-f', stdout)
     self.assertIn('test-g', stdout)
     util.rmRf(test_dir)
Exemple #6
0
    def testLinkedBuild(self):
        linked_in_module = util.writeTestFiles(util.Test_Trivial_Lib, True)
        test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep, True)

        stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'link'], cwd=linked_in_module)
        self.assertEqual(statuscode, 0)
        stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'link', 'test-trivial-lib'], cwd=test_module)
        self.assertEqual(statuscode, 0)
        stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'build'], cwd=test_module)
        self.assertEqual(statuscode, 0)

        util.rmRf(test_module)
        util.rmRf(linked_in_module)
Exemple #7
0
    def testUnlinkModule(self):
        linked_in_module = util.writeTestFiles(util.Test_Trivial_Lib, True)
        test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep, True)

        stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'link'], cwd=linked_in_module)
        self.assertEqual(statuscode, 0)
        stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'link', 'test-trivial-lib'], cwd=test_module)
        self.assertEqual(statuscode, 0)
        self.assertTrue(os.path.exists(os.path.join(test_module, 'yotta_modules', 'test-trivial-lib')))
        stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'unlink', 'test-trivial-lib'], cwd=test_module)
        self.assertEqual(statuscode, 0)
        self.assertTrue(not os.path.exists(os.path.join(test_module, 'yotta_modules', 'test-trivial-lib')))

        util.rmRf(test_module)
        util.rmRf(linked_in_module)
Exemple #8
0
 def test_binNonExistent(self):
     test_dir = util.writeTestFiles(Test_Bin_Nonexistent)
     stdout, stderr, statuscode = cli.run(['--target', util.nativeTarget(), 'build'], cwd=test_dir)
     self.assertIn('directory "doesntexist" doesn\'t exist', stdout+stderr)
     # !!! FIXME: should this error be fatal?
     # self.assertNotEqual(statuscode, 0)
     util.rmRf(test_dir)
Exemple #9
0
 def test_yottaVersionCheckOKBuilding(self):
     test_dir = util.writeTestFiles(Test_Min_Version_OK)
     stdout, stderr, statuscode = cli.run(
         ['--target', util.nativeTarget(), 'build'], cwd=test_dir)
     self.assertEqual(statuscode, 0)
     self.assertNotIn('requires yotta version >', stdout + stderr)
     util.rmRf(test_dir)
Exemple #10
0
    def test_buildTrivialExe(self):
        test_dir = util.writeTestFiles(util.Test_Trivial_Exe)

        stdout = self.runCheckCommand(
            ['--target', util.nativeTarget(), 'build'], test_dir)

        util.rmRf(test_dir)
Exemple #11
0
    def test_buildComplexSpaceInPath(self):
        test_dir = util.writeTestFiles(Test_Complex, True)

        stdout = self.runCheckCommand(
            ['--target', util.nativeTarget(), 'build'], test_dir)

        util.rmRf(test_dir)
Exemple #12
0
def _nopDebugTargetDescription(name):
    native_target = util.nativeTarget()
    if ',' in native_target:
        native_target = native_target[:native_target.find(',')]
    return {
    'target.json':'''{
      "name": "%s",
      "version": "1.0.0",
      "license": "Apache-2.0",
      "inherits": {
        "%s": "*"
      },
      "scripts": {
        "debug": ["./scripts/nop.py", "$program", "$build_dir", "$target_dir"]
      }
    }
    ''' % (name, native_target),
    './scripts/nop.py':'''
import os
import sys
import json

env_keys = ["YOTTA_PROGRAM", "YOTTA_BUILD_DIR", "YOTTA_TARGET_DIR"]
print(json.dumps({"argv": sys.argv[1:], "env": {k: v for k, v in os.environ.items() if k in env_keys}}))
print('%s')
    ''' % JSON_MARKER
    }
Exemple #13
0
def _nopDebugTargetDescription(name):
    native_target = util.nativeTarget()
    if ',' in native_target:
        native_target = native_target[:native_target.find(',')]
    return {
        'target.json':
        '''{
      "name": "%s",
      "version": "1.0.0",
      "license": "Apache-2.0",
      "inherits": {
        "%s": "*"
      },
      "scripts": {
        "debug": ["./scripts/nop.py", "$program", "$build_dir", "$target_dir"]
      }
    }
    ''' % (name, native_target),
        './scripts/nop.py':
        '''
import os
import sys
import json

env_keys = ["YOTTA_PROGRAM", "YOTTA_BUILD_DIR", "YOTTA_TARGET_DIR"]
print(json.dumps({"argv": sys.argv[1:], "env": {k: v for k, v in os.environ.items() if k in env_keys}}))
print('%s')
    ''' % JSON_MARKER
    }
Exemple #14
0
 def test_Defines_Library(self):
     test_dir = util.writeTestFiles(Test_Defines_Library)
     stdout = self.runCheckCommand(
         ['--target', util.nativeTarget(), 'build'], test_dir)
     self.assertIn(
         "defines.json ignored in library module 'test-defines-lib'",
         stdout)
     util.rmRf(test_dir)
Exemple #15
0
 def test_libAndBinSpecified(self):
     test_dir = util.writeTestFiles(Test_Lib_And_Bin)
     stdout, stderr, statuscode = cli.run(
         ['--target', util.nativeTarget(), 'build'], cwd=test_dir)
     self.assertNotEqual(statuscode, 0)
     self.assertIn(
         'Both "lib" and "bin" are specified in module.json: only one is allowed',
         stdout + stderr)
     util.rmRf(test_dir)
Exemple #16
0
    def testLinkedBuild(self):
        linked_in_module = util.writeTestFiles(util.Test_Trivial_Lib, True)
        test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep,
                                          True)

        stdout, stderr, statuscode = cli.run(
            ['-t', util.nativeTarget(), '--plain', 'link'],
            cwd=linked_in_module)
        self.assertEqual(statuscode, 0)
        stdout, stderr, statuscode = cli.run(
            ['-t',
             util.nativeTarget(), '--plain', 'link', 'test-trivial-lib'],
            cwd=test_module)
        self.assertEqual(statuscode, 0)
        stdout, stderr, statuscode = cli.run(
            ['-t', util.nativeTarget(), '--plain', 'build'], cwd=test_module)
        self.assertEqual(statuscode, 0)

        util.rmRf(test_module)
        util.rmRf(linked_in_module)
Exemple #17
0
    def testLinkedReBuild(self):
        # test that changing which module is linked triggers a re-build
        linked_in_module_1 = util.writeTestFiles(util.Test_Trivial_Lib, True)
        linked_in_module_2 = util.writeTestFiles(util.Test_Trivial_Lib, True)
        test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep, True)

        stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'link'], cwd=linked_in_module_1)
        self.assertEqual(statuscode, 0)
        stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'link', 'test-trivial-lib'], cwd=test_module)
        self.assertEqual(statuscode, 0)
        stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'build'], cwd=test_module)
        self.assertEqual(statuscode, 0)

        # check that rebuild is no-op
        stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'build'], cwd=test_module)
        self.assertIn('no work to do', stdout+stderr)
        self.assertEqual(statuscode, 0)

        stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'link'], cwd=linked_in_module_2)
        self.assertEqual(statuscode, 0)

        stdout, stderr, statuscode = cli.run(['-t', util.nativeTarget(), '--plain', 'build'], cwd=test_module)
        self.assertNotIn('no work to do', stdout+stderr)
        self.assertEqual(statuscode, 0)

        util.rmRf(test_module)
        util.rmRf(linked_in_module_1)
        util.rmRf(linked_in_module_2)
Exemple #18
0
    def test_buildInfo(self):
        test_dir = util.writeTestFiles(Test_Build_Info, True)
        # commit all the test files to git so that the VCS build info gets
        # defined:
        # (set up the git user env vars so we can run git commit without barfing)
        util.setupGitUser()
        subprocess.check_call(['git', 'init', '-q'], cwd=test_dir)
        subprocess.check_call(['git', 'add', '.'], cwd=test_dir)
        subprocess.check_call(['git', 'commit', '-m', 'test build info automated commit', '-q'], cwd=test_dir)

        self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)

        build_time = datetime.datetime.utcnow()
        output = subprocess.check_output(['./build/' + util.nativeTarget().split(',')[0] + '/source/test-trivial-exe'], cwd=test_dir).decode()
        self.assertIn('vcs clean: 1', output)

        # check build timestamp
        self.assertIn('build timestamp: ', output)
        build_timestamp_s = re.search('build timestamp: (.*)\n', output)
        self.assertTrue(build_timestamp_s)
        build_timestamp_s = build_timestamp_s.group(1)
        build_time_parsed = datetime.datetime.strptime(build_timestamp_s, '%Y-%m-%d-%H-%M-%S')
        build_time_skew = build_time_parsed - build_time
        self.assertTrue(abs(build_time_skew.total_seconds()) < 3)
Exemple #19
0
    def test_postInstall_dependency(self):
        test_dir = util.writeTestFiles({
'module.json':'''{
  "name": "test-postinstall",
  "version": "1.0.0",
  "license": "Apache-2.0",
  "dependencies": {
    "test-post-install": "*"
  },
  "bin":"./source"
}''',

'source/lib.c':'''
#include <stdio.h>
#include "test-post-install/generated.h"
int main(){ printf("generated return val=%d\\n", postInstallGenerated()); return 0; }
'''})
        output = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
        self.assertIn('post-install generated file compiled', output)
        self.assertIn('post-install generated header file included', output)
        self.assertIn('generated .cmake file included', output)
Exemple #20
0
def _nopStartTargetDescription(name):
    native_target = util.nativeTarget()
    if ',' in native_target:
        native_target = native_target[:native_target.find(',')]
    return {
    'target.json':'''{
      "name": "%s",
      "version": "1.0.0",
      "license": "Apache-2.0",
      "inherits": {
        "%s": "*"
      },
      "scripts": {
        "start": ["./scripts/nop.py", "$program"]
      }
    }
    ''' % (name, native_target),
    './scripts/nop.py':'''
import os
print('would start %s' % os.environ['YOTTA_PROGRAM'])
    '''
    }
Exemple #21
0
    def test_postInstall_dependency(self):
        test_dir = util.writeTestFiles({
            'module.json':
            '''{
  "name": "test-postinstall",
  "version": "1.0.0",
  "license": "Apache-2.0",
  "dependencies": {
    "test-post-install": "*"
  },
  "bin":"./source"
}''',
            'source/lib.c':
            '''
#include <stdio.h>
#include "test-post-install/generated.h"
int main(){ printf("generated return val=%d\\n", postInstallGenerated()); return 0; }
'''
        })
        output = self.runCheckCommand(
            ['--target', util.nativeTarget(), 'build'], test_dir)
        self.assertIn('post-install generated file compiled', output)
        self.assertIn('post-install generated header file included', output)
        self.assertIn('generated .cmake file included', output)
Exemple #22
0
    def testLinkedReBuild(self):
        # test that changing which module is linked triggers a re-build
        linked_in_module_1 = util.writeTestFiles(util.Test_Trivial_Lib, True)
        linked_in_module_2 = util.writeTestFiles(util.Test_Trivial_Lib, True)
        test_module = util.writeTestFiles(util.Test_Testing_Trivial_Lib_Dep,
                                          True)

        stdout, stderr, statuscode = cli.run(
            ['-t', util.nativeTarget(), '--plain', 'link'],
            cwd=linked_in_module_1)
        self.assertEqual(statuscode, 0)
        stdout, stderr, statuscode = cli.run(
            ['-t',
             util.nativeTarget(), '--plain', 'link', 'test-trivial-lib'],
            cwd=test_module)
        self.assertEqual(statuscode, 0)
        stdout, stderr, statuscode = cli.run(
            ['-t', util.nativeTarget(), '--plain', 'build'], cwd=test_module)
        self.assertEqual(statuscode, 0)

        # check that rebuild is no-op
        stdout, stderr, statuscode = cli.run(
            ['-t', util.nativeTarget(), '--plain', 'build'], cwd=test_module)
        self.assertIn('no work to do', stdout + stderr)
        self.assertEqual(statuscode, 0)

        stdout, stderr, statuscode = cli.run(
            ['-t', util.nativeTarget(), '--plain', 'link'],
            cwd=linked_in_module_2)
        self.assertEqual(statuscode, 0)

        stdout, stderr, statuscode = cli.run(
            ['-t', util.nativeTarget(), '--plain', 'build'], cwd=test_module)
        self.assertNotIn('no work to do', stdout + stderr)
        self.assertEqual(statuscode, 0)

        util.rmRf(test_module)
        util.rmRf(linked_in_module_1)
        util.rmRf(linked_in_module_2)
Exemple #23
0
    def test_buildComplexSpaceInPath(self):
        test_dir = util.writeTestFiles(Test_Complex, True)

        stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)

        util.rmRf(test_dir)
Exemple #24
0
 def test_customBinSubSourceDir(self):
     test_dir = util.writeTestFiles(Test_Custom_Bin_Sub_Source_Dir, True)
     stdout = self.runCheckCommand(
         ['--target', util.nativeTarget(), 'build'], test_dir)
     self.assertIn('this message should be printed', stdout)
     util.rmRf(test_dir)
Exemple #25
0
 def test_ignoreCustomCMake(self):
     test_dir = util.writeTestFiles(Test_Ignore_Custom_Cmake, True)
     stdout = self.runCheckCommand(
         ['--target', util.nativeTarget(), 'build'], test_dir)
     self.assertNotIn('should be ignored', stdout)
     util.rmRf(test_dir)
Exemple #26
0
    def test_buildTrivialExe(self):
        test_dir = util.writeTestFiles(util.Test_Trivial_Exe)

        stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)

        util.rmRf(test_dir)
Exemple #27
0
 def test_native_start(self):
     test_dir = util.writeTestFiles(util.Test_Trivial_Exe, True)
     output = util.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
     output = util.runCheckCommand(['--target', util.nativeTarget(), 'start'], test_dir)
     self.assertIn('[trivial-exe-running]', output)
     util.rmRf(test_dir)
Exemple #28
0
 def test_customCMakeBuildExe(self):
     test_dir = util.writeTestFiles(util.Test_Custom_CMake_Exe, True)
     stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
     util.rmRf(test_dir)
Exemple #29
0
 def test_scriptsPreGenerate(self):
     test_dir = util.writeTestFiles(Test_Scripts_PreGenerate)
     stdout = self.runCheckCommand(
         ['--target', util.nativeTarget(), 'build'], test_dir)
     self.assertIn("running pregenerate", stdout)
     util.rmRf(test_dir)
Exemple #30
0
 def test_customBinSubSourceDir(self):
     test_dir = util.writeTestFiles(Test_Custom_Bin_Sub_Source_Dir, True)
     stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
     self.assertIn('this message should be printed', stdout)
     util.rmRf(test_dir)
Exemple #31
0
 def test_ignoreCustomCMake(self):
     test_dir = util.writeTestFiles(Test_Ignore_Custom_Cmake, True)
     stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
     self.assertNotIn('should be ignored', stdout)
     util.rmRf(test_dir)
Exemple #32
0
 def test_libAndBinSpecified(self):
     test_dir = util.writeTestFiles(Test_Lib_And_Bin)
     stdout, stderr, statuscode = cli.run(['--target', util.nativeTarget(), 'build'], cwd=test_dir)
     self.assertNotEqual(statuscode, 0)
     self.assertIn('Both "lib" and "bin" are specified in module.json: only one is allowed', stdout+stderr)
     util.rmRf(test_dir)
Exemple #33
0
 def test_scriptsPreGenerate(self):
     test_dir = util.writeTestFiles(Test_Scripts_PreGenerate)
     stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
     self.assertIn("running pregenerate", stdout)
     util.rmRf(test_dir)
Exemple #34
0
 def test_misspeltSourceDirIgnored(self):
     test_dir = util.writeTestFiles(Test_Ignored_Misspelt_Source_Dir)
     stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
     self.assertNotIn("has non-standard source directory name", stdout)
     util.rmRf(test_dir)
Exemple #35
0
 def test_misspeltSourceDirIgnored(self):
     test_dir = util.writeTestFiles(Test_Ignored_Misspelt_Source_Dir)
     stdout = self.runCheckCommand(
         ['--target', util.nativeTarget(), 'build'], test_dir)
     self.assertNotIn("has non-standard source directory name", stdout)
     util.rmRf(test_dir)
Exemple #36
0
 def test_extraCMakeBuild(self):
     test_dir = util.writeTestFiles(util.Test_Extra_CMake_Lib, True)
     stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
     util.rmRf(test_dir)
Exemple #37
0
 def test_scriptsPostBuild(self):
     test_dir = util.writeTestFiles(Test_Scripts_PostBuild)
     stdout = self.runCheckCommand(
         ['--target', util.nativeTarget(), 'build'], test_dir)
     self.assertIn("running postbuild", stdout)
     util.rmRf(test_dir)
Exemple #38
0
 def test_Defines_Library(self):
     test_dir = util.writeTestFiles(Test_Defines_Library)
     stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
     self.assertIn("defines.json ignored in library module 'test-defines-lib'", stdout)
     util.rmRf(test_dir)
Exemple #39
0
 def test_yottaVersionCheckOKBuilding(self):
     test_dir = util.writeTestFiles(Test_Min_Version_OK)
     stdout, stderr, statuscode = cli.run(['--target', util.nativeTarget(), 'build'], cwd=test_dir)
     self.assertEqual(statuscode, 0)
     self.assertNotIn('requires yotta version >', stdout+stderr)
     util.rmRf(test_dir)
Exemple #40
0
 def test_extraCMakeBuild(self):
     test_dir = util.writeTestFiles(util.Test_Extra_CMake_Lib, True)
     stdout = self.runCheckCommand(
         ['--target', util.nativeTarget(), 'build'], test_dir)
     util.rmRf(test_dir)
Exemple #41
0
 def test_Toplevel_Library(self):
     test_dir = util.writeTestFiles(Test_Toplevel_Library)
     stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
     output = subprocess.check_output(['./build/' + util.nativeTarget().split(',')[0] + '/test/test-toplevel-lib-test-test'], cwd=test_dir).decode()
     self.assertIn("42", output)
     util.rmRf(test_dir)
Exemple #42
0
 def test_customCMakeBuildExe(self):
     test_dir = util.writeTestFiles(util.Test_Custom_CMake_Exe, True)
     stdout = self.runCheckCommand(
         ['--target', util.nativeTarget(), 'build'], test_dir)
     util.rmRf(test_dir)
Exemple #43
0
 def test_Defines_Application(self):
     test_dir = util.writeTestFiles(Test_Defines_Application)
     stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
     output = subprocess.check_output(['./build/' + util.nativeTarget().split(',')[0] + '/source/test-defines-app'], cwd=test_dir).decode()
     self.assertIn("1234 yotta", output)
     util.rmRf(test_dir)
Exemple #44
0
 def test_scriptsPostBuild(self):
     test_dir = util.writeTestFiles(Test_Scripts_PostBuild)
     stdout = self.runCheckCommand(['--target', util.nativeTarget(), 'build'], test_dir)
     self.assertIn("running postbuild", stdout)
     util.rmRf(test_dir)