Esempio n. 1
0
 def test_get_config_by_dir_bad_dir(self):
     ''' Test get_config_by_dir() when dir is invalid. '''
     bad_dir = os.path.join(self.simdir, 'sim')
     try:
         _ = zsimparse.get_config_by_dir(bad_dir)
     except ValueError as e:
         self.assertIn('cfg', str(e))
Esempio n. 2
0
    def test_config_get_invalid_names(self):
        ''' Test config_get() with invalid names. '''
        cfg = zsimparse.get_config_by_dir(self.simdir)
        cfg.raw['list'] = [1, 2, 3]

        self.assertIsNone(zsimparse.config_get(cfg, ('g1', 's2')))
        self.assertIsNone(zsimparse.config_get(cfg, 'g1 s1 t3'))
        self.assertIsNone(zsimparse.config_get(cfg, 'g4'))

        with self.assertRaises(KeyError):
            _ = cfg['g1']['s2']
        with self.assertRaises(KeyError):
            _ = cfg['g1']['s1']['t3']
        with self.assertRaises(IndexError):
            _ = cfg['list'][4]
        with self.assertRaises(TypeError):
            _ = cfg['sys']['frequency'][1]

        with self.assertRaises(KeyError):
            _ = cfg.g1.s2
        with self.assertRaises(KeyError):
            _ = cfg.g1.s1.t3
        with self.assertRaises(IndexError):
            _ = cfg.list[4]
        with self.assertRaises(TypeError):
            _ = cfg.sys.frequency[1]
Esempio n. 3
0
 def setUp(self):
     # Example sim directory.
     self.simdir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                'simdir')
     # Get config.
     self.cfg = zsimparse.get_config_by_dir(self.simdir)
     # Get hdf5 dataset.
     self.dset = zsimparse.get_hdf5_by_dir(self.simdir, final_only=True)
Esempio n. 4
0
    def test_config_get(self):
        ''' Test config_get(). '''
        cfg = zsimparse.get_config_by_dir(self.simdir)
        cfg.raw['list'] = [1, 2, 3]

        self.assertEqual(
            zsimparse.config_get(cfg, ('sys', 'caches', 'l1d', 'size')), 65536)
        self.assertEqual(zsimparse.config_get(cfg, ('list', 1)), 2)
        self.assertEqual(zsimparse.config_get(cfg, 'sys caches l1d type'),
                         'Simple')
        self.assertEqual(zsimparse.config_get(cfg, 'sim.maxTotalInstrs'),
                         libconf.LibconfInt64(0))

        self.assertEqual(cfg['sys']['caches']['l1d']['size'], 65536)
        self.assertEqual(cfg['list'][1], 2)
        self.assertEqual(cfg['sys']['caches']['l1d']['type'], 'Simple')
        self.assertEqual(cfg['sim']['maxTotalInstrs'], libconf.LibconfInt64(0))

        self.assertEqual(cfg.sys.caches.l1d.size, 65536)
        self.assertEqual(cfg.sys.caches.l1d.type, 'Simple')
        self.assertEqual(cfg.sim.maxTotalInstrs, libconf.LibconfInt64(0))
Esempio n. 5
0
 def test_get_config_by_dir_bad_dir(self):
     ''' Test get_config_by_dir() when dir is invalid. '''
     bad_dir = os.path.join(self.simdir, 'sim')
     with self.assertRaisesRegex(ValueError, '.*cfg.*'):
         _ = zsimparse.get_config_by_dir(bad_dir)
Esempio n. 6
0
 def test_get_config_by_dir(self):
     ''' Test get_config_by_dir(). '''
     cfg = zsimparse.get_config_by_dir(self.simdir)
     self.assertIsNotNone(cfg)
     self.assertIsNotNone(zsimparse.config_get(cfg, 'sys'))
Esempio n. 7
0
 def test_config_lookup(self):
     ''' Test lookup(). '''
     val = zsimparse.get_config_by_dir(self.simdir)
     for key in ('sys', 'caches', 'l1d', 'size'):
         val = val.lookup(key)
     self.assertEqual(val.raw, 65536)