zackliqcom commited on
Commit
f2f6076
·
verified ·
1 Parent(s): 31dadc6

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. __pycache__/utils.cpython-312.pyc +0 -0
  2. conftest.py +5 -1
  3. utils.py +78 -10
__pycache__/utils.cpython-312.pyc ADDED
Binary file (7.77 kB). View file
 
conftest.py CHANGED
@@ -4,15 +4,19 @@
4
  # ---------------------------------------------------------------------
5
  """Shared pytest fixtures for QDC on-device test runners (Linux IoT)."""
6
 
 
7
  import os
8
 
9
  import pytest
10
 
11
- from utils import write_qdc_log
 
 
12
 
13
 
14
  @pytest.fixture(scope="session", autouse=True)
15
  def driver():
 
16
  return None
17
 
18
 
 
4
  # ---------------------------------------------------------------------
5
  """Shared pytest fixtures for QDC on-device test runners (Linux IoT)."""
6
 
7
+ import logging
8
  import os
9
 
10
  import pytest
11
 
12
+ from utils import log_environment, write_qdc_log
13
+
14
+ logging.basicConfig(level=logging.INFO, format="%(name)s %(levelname)s: %(message)s")
15
 
16
 
17
  @pytest.fixture(scope="session", autouse=True)
18
  def driver():
19
+ log_environment()
20
  return None
21
 
22
 
utils.py CHANGED
@@ -4,10 +4,13 @@
4
  # ---------------------------------------------------------------------
5
  """Shared helpers for QDC on-device test runners (Linux IoT)."""
6
 
 
7
  import os
8
  import shutil
9
  import subprocess
10
 
 
 
11
  # ---------------------------------------------------------------------------
12
  # On-device paths
13
  # ---------------------------------------------------------------------------
@@ -27,14 +30,25 @@ CMD_PREFIX = f"cd {BUNDLE_PATH} && {ENV_PREFIX}"
27
  # Shell helpers
28
  # ---------------------------------------------------------------------------
29
 
30
- def run_shell_command(cmd: str, *, check: bool = True) -> subprocess.CompletedProcess:
31
- result = subprocess.run(
32
- ["sh", "-c", cmd],
33
- text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
34
- )
 
 
 
 
 
 
 
35
  print(result.stdout)
36
  if check:
37
- assert result.returncode == 0, f"Command failed (exit {result.returncode})"
 
 
 
 
38
  return result
39
 
40
 
@@ -45,10 +59,64 @@ def write_qdc_log(filename: str, content: str) -> None:
45
  f.write(content)
46
 
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  def push_bundle_if_needed(check_binary: str) -> None:
49
  """Copy llama_cpp_bundle to /tmp if check_binary is not already present."""
 
 
 
 
 
 
 
 
 
50
  if not os.path.exists(check_binary):
51
- src = "/qdc/appium/llama_cpp_bundle"
52
- if os.path.isdir(src):
53
- shutil.copytree(src, BUNDLE_PATH, dirs_exist_ok=True)
54
- subprocess.run(["chmod", "-R", "+x", BIN_PATH], check=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  # ---------------------------------------------------------------------
5
  """Shared helpers for QDC on-device test runners (Linux IoT)."""
6
 
7
+ import logging
8
  import os
9
  import shutil
10
  import subprocess
11
 
12
+ log = logging.getLogger(__name__)
13
+
14
  # ---------------------------------------------------------------------------
15
  # On-device paths
16
  # ---------------------------------------------------------------------------
 
30
  # Shell helpers
31
  # ---------------------------------------------------------------------------
32
 
33
+ def run_shell_command(cmd: str, *, check: bool = True, timeout: int = 600) -> subprocess.CompletedProcess:
34
+ log.info("Running: %s", cmd[:200])
35
+ try:
36
+ result = subprocess.run(
37
+ ["sh", "-c", cmd],
38
+ text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
39
+ timeout=timeout,
40
+ )
41
+ except subprocess.TimeoutExpired as e:
42
+ output = e.stdout or ""
43
+ print(output)
44
+ raise AssertionError(f"Command timed out after {timeout}s") from e
45
  print(result.stdout)
46
  if check:
47
+ assert result.returncode == 0, (
48
+ f"Command failed (exit {result.returncode}):\n"
49
+ f" cmd: {cmd[:200]}\n"
50
+ f" last 500 chars of output: {(result.stdout or '')[-500:]}"
51
+ )
52
  return result
53
 
54
 
 
59
  f.write(content)
60
 
61
 
62
+ def _find_bundle_source() -> str:
63
+ """Locate the llama_cpp_bundle directory from the QDC extraction."""
64
+ candidates = [
65
+ os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "llama_cpp_bundle"),
66
+ "/qdc/appium/llama_cpp_bundle",
67
+ "/qdc/bash/llama_cpp_bundle",
68
+ ]
69
+ for c in candidates:
70
+ real = os.path.realpath(c)
71
+ if os.path.isdir(real):
72
+ log.info("Found bundle source at %s", real)
73
+ return real
74
+ # Debug: dump known directories to help diagnose
75
+ for check_dir in ["/qdc", "/qdc/appium", "/qdc/bash",
76
+ os.path.dirname(os.path.abspath(__file__)),
77
+ os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")]:
78
+ if os.path.isdir(check_dir):
79
+ log.info("[debug] %s: %s", check_dir, os.listdir(check_dir))
80
+ else:
81
+ log.info("[debug] %s: does not exist", check_dir)
82
+ raise FileNotFoundError("llama_cpp_bundle not found in any known QDC extraction path")
83
+
84
+
85
  def push_bundle_if_needed(check_binary: str) -> None:
86
  """Copy llama_cpp_bundle to /tmp if check_binary is not already present."""
87
+ if os.path.exists(check_binary):
88
+ log.info("Binary already present: %s", check_binary)
89
+ return
90
+
91
+ src = _find_bundle_source()
92
+ log.info("Copying bundle from %s to %s", src, BUNDLE_PATH)
93
+ shutil.copytree(src, BUNDLE_PATH, dirs_exist_ok=True)
94
+ subprocess.run(["chmod", "-R", "+x", BIN_PATH], check=False)
95
+
96
  if not os.path.exists(check_binary):
97
+ available = os.listdir(BIN_PATH) if os.path.isdir(BIN_PATH) else []
98
+ raise FileNotFoundError(
99
+ f"Binary {check_binary} not found after bundle copy. "
100
+ f"Available binaries: {available}"
101
+ )
102
+ log.info("Bundle installed, verified %s exists", check_binary)
103
+
104
+
105
+ def log_environment() -> None:
106
+ """Log environment info for debugging."""
107
+ script_dir = os.path.dirname(os.path.abspath(__file__))
108
+ parent_dir = os.path.dirname(script_dir)
109
+ lines = [
110
+ f"__file__: {os.path.abspath(__file__)}",
111
+ f"script_dir: {script_dir}",
112
+ f"parent_dir contents: {os.listdir(parent_dir) if os.path.isdir(parent_dir) else 'missing'}",
113
+ f"BUNDLE_PATH exists: {os.path.isdir(BUNDLE_PATH)}",
114
+ f"BIN_PATH contents: {os.listdir(BIN_PATH) if os.path.isdir(BIN_PATH) else 'missing'}",
115
+ f"LIB_PATH contents: {os.listdir(LIB_PATH) if os.path.isdir(LIB_PATH) else 'missing'}",
116
+ f"LD_LIBRARY_PATH: {os.environ.get('LD_LIBRARY_PATH', 'not set')}",
117
+ f"/qdc/appium/ contents: {os.listdir('/qdc/appium/') if os.path.isdir('/qdc/appium/') else 'missing'}",
118
+ f"/qdc/bash/ contents: {os.listdir('/qdc/bash/') if os.path.isdir('/qdc/bash/') else 'missing'}",
119
+ ]
120
+ for line in lines:
121
+ log.info("[env] %s", line)
122
+ write_qdc_log("environment.log", "\n".join(lines) + "\n")