Exemplo n.º 1
0
    def test_GetMem_meminfo(self):
        """
        """
        print("")
        si = sysinfo.SysInfo()

        # Force SysInfo to use the meminfo method.
        si.have_psutil = False

        if not si.have_psutil:
            mo = mock.mock_open(read_data=self._meminfo)

            builtins_open = "{}.open".format(self._builtins())

            meminfo = None
            with patch(builtins_open, mo) as m:
                meminfo = si.meminfo

            print("SysInfo.meminfo = {}".format(meminfo))
            print("- mem_kb = {}".format(meminfo['mem_kb']))
            print("- mem_gb = {}".format(meminfo['mem_gb']))

            m.assert_called_once()
            self.assertEqual(67108864, int(meminfo['mem_kb']))
            self.assertEqual(64, int(meminfo['mem_gb']))
Exemplo n.º 2
0
 def test_SysInfo_have_psutil_error(self):
     """
     Test that a TypeError is raised if we try to assign something other than a
     bool to SysInfo.have_psutil
     """
     print("")
     si = sysinfo.SysInfo()
     with self.assertRaises(TypeError):
         si.have_psutil = "XXX"
Exemplo n.º 3
0
    def test_GetMem_psutil(self):
        """
        """
        print("")
        si = sysinfo.SysInfo()

        # Force SysInfo to use the psutil method (we mock this so even if psutil isn't
        # available this should work)
        si.have_psutil = True

        if si.have_psutil:
            meminfo = None
            with patch(
                    "trilinosprhelpers.sysinfo.SysInfo._get_psutil_vm_total",
                    side_effect=mock_psutil_vm_total) as m:
                meminfo = si.meminfo

            print("SysInfo.meminfo = {}".format(meminfo))
            print("- mem_kb = {}".format(meminfo['mem_kb']))
            print("- mem_gb = {}".format(meminfo['mem_gb']))

            m.assert_called_once()
            self.assertEqual(67108864, int(meminfo['mem_kb']))
            self.assertEqual(64, int(meminfo['mem_gb']))
Exemplo n.º 4
0
    def test_compute_num_usable_cores(self):
        # compute_num_usable_cores(self, req_mem_gb_per_core=3.0, max_cores_allowed=32):
        si = sysinfo.SysInfo()
        si.have_psutil = True

        if si.have_psutil:
            meminfo = None
            with patch(
                    "trilinosprhelpers.sysinfo.SysInfo._get_psutil_vm_total",
                    side_effect=mock_psutil_vm_total) as m:
                meminfo = si.meminfo

                print("SysInfo.meminfo = {}".format(meminfo))
                print("- mem_kb = {}".format(meminfo['mem_kb']))
                print("- mem_gb = {}".format(meminfo['mem_gb']))

                # For all:
                # sys memory: 64 GB  (mocked)
                # sys cpus  : 20     (mocked)

                # Test Case:
                # req memory: 6 GB / Core
                # max cores : 3
                # expected  : 3
                with patch("multiprocessing.cpu_count",
                           side_effect=mock_multiprocessing_cpu_count) as m:
                    n = si.compute_num_usable_cores(6, 3)
                    print("- n = {}".format(n))
                    self.assertEqual(3, n)
                    m.assert_called_once()

                # Test Case:
                # req memory: 1 GB / Core
                # max cores : 32
                # expected  : 20
                with patch("multiprocessing.cpu_count",
                           side_effect=mock_multiprocessing_cpu_count) as m:
                    n = si.compute_num_usable_cores(1, 32)
                    print("- n = {}".format(n))
                    self.assertEqual(20, n)
                    m.assert_called_once()

                # Test Case:
                # req memory: 5 GB / Core
                # max cores : 32
                # expected  : 12
                with patch("multiprocessing.cpu_count",
                           side_effect=mock_multiprocessing_cpu_count) as m:
                    n = si.compute_num_usable_cores(5, 32)
                    print("- n = {}".format(n))
                    self.assertEqual(12, n)
                    m.assert_called_once()

                # Test Case:
                # req memory: 5 GB / Core
                # max cores : 0
                # expected  : 1
                with patch("multiprocessing.cpu_count",
                           side_effect=mock_multiprocessing_cpu_count) as m:
                    n = si.compute_num_usable_cores(5, 0)
                    print("- n = {}".format(n))
                    self.assertEqual(1, n)
                    m.assert_called_once()