From f251554f487088211328d98af4c4958ff06b75d3 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 30 Jan 2021 22:46:47 +0100 Subject: [PATCH 1/2] main: Fix options parsing to match man page --gpu=X was documented, but --gpu X was expected. Fix both to work. --- src/switcherooctl.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/switcherooctl.in b/src/switcherooctl.in index fde7dba..36623a2 100755 --- a/src/switcherooctl.in +++ b/src/switcherooctl.in @@ -166,7 +166,9 @@ elif command == 'version': elif command == 'launch': if len(args) == 0: sys.exit(0) - if args[0] == '--gpu' or args[0] == '-g': + if args[0][:5] == '--gpu' or args[0] == '-g': + if args[0][:6] == '--gpu=': + args = args[0].split('=') + args[1:] if len(args) == 2: sys.exit(0) if len(args) == 1: -- GitLab From 6b5dd1fd4f98427c474d74879457110bed87b829 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 30 Jan 2021 22:47:59 +0100 Subject: [PATCH 2/2] tests: Add tests for the command-line tool --- tests/integration-test | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/integration-test b/tests/integration-test index fe9be17..562f01c 100755 --- a/tests/integration-test +++ b/tests/integration-test @@ -384,6 +384,32 @@ class Tests(dbusmock.DBusTestCase): self.stop_daemon() + def test_cmdline_tool(self): + '''test the command-line tool''' + + self.add_intel_gpu() + self.add_nouveau_gpu() + self.start_daemon() + + builddir = os.getenv('top_builddir', '.') + tool_path = os.path.join(builddir, 'src', 'switcherooctl') + + out = subprocess.run([tool_path], capture_output=True) + self.assertEqual(out.returncode, 0, "'switcherooctl' call failed") + self.assertEqual(out.stdout, b'Device: 0\n Name: Intel\xc2\xae UHD Graphics 620 (Kabylake GT2)\n Default: yes\n Environment: DRI_PRIME=pci-0000_00_02_0\n\nDevice: 1\n Name: GM108M [GeForce 930MX]\n Default: no\n Environment: DRI_PRIME=pci-0000_01_00_0\n') + + out = subprocess.run([tool_path, 'launch', '--gpu', '0', 'env'], capture_output=True) + self.assertEqual(out.returncode, 0, "'switcherooctl launch --gpu 0' failed") + assert('DRI_PRIME=pci-0000_00_02_0' in str(out.stdout)) + + out = subprocess.run([tool_path, 'launch', '--gpu', '1', 'env'], capture_output=True) + self.assertEqual(out.returncode, 0, "'switcherooctl launch --gpu 1' failed") + assert('DRI_PRIME=pci-0000_01_00_0' in str(out.stdout)) + + out = subprocess.run([tool_path, 'launch', '--gpu=1', 'env'], capture_output=True) + self.assertEqual(out.returncode, 0, "'switcherooctl launch --gpu=1' failed") + assert('DRI_PRIME=pci-0000_01_00_0' in str(out.stdout)) + # # Helper methods # -- GitLab