File: test_backend_loading.py

package info (click to toggle)
basis-universal 2.0.2-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 216,436 kB
  • sloc: cpp: 163,224; ansic: 51,368; python: 2,824; javascript: 2,637; lisp: 1,026; sh: 161; makefile: 17
file content (70 lines) | stat: -rw-r--r-- 2,151 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
import numpy as np
from PIL import Image

from basisu_py.codec import Encoder, EncoderBackend
from basisu_py.constants import BasisTexFormat

print("========== BACKEND LOADING TEST ==========\n")

# --------------------------------------------------------------
# 1. Test native backend (if available)
# --------------------------------------------------------------
print("Testing native backend...")

try:
    enc_native = Encoder(backend=EncoderBackend.NATIVE)
    print("  [OK] Native backend loaded")
except Exception as e:
    print("  [FAIL] Native backend failed to load:", e)
    enc_native = None

# If native loaded, test very basic functionality
if enc_native:
    try:
        version = enc_native._native.get_version()
        print(f"  Native get_version() ? {version}")

        ptr = enc_native._native.alloc(16)
        print(f"  Native alloc() returned ptr = {ptr}")

        enc_native._native.free(ptr)
        print(f"  Native free() OK")

        print("  [OK] Native basic operations working.\n")
    except Exception as e:
        print("  [FAIL] Native operations error:", e)
else:
    print("  Skipping native basic operations.\n")

# --------------------------------------------------------------
# 2. Test WASM backend
# --------------------------------------------------------------
print("\nTesting WASM backend...")

try:
    enc_wasm = Encoder(backend=EncoderBackend.WASM)
    print("  [OK] WASM backend loaded")
except Exception as e:
    print("  [FAIL] WASM backend failed to load:", e)
    enc_wasm = None

# If WASM loaded, test basic methods
if enc_wasm and enc_wasm._wasm is not None:
    try:
        version = enc_wasm._wasm.get_version()
        print(f"  WASM get_version() ? {version}")

        ptr = enc_wasm._wasm.alloc(16)
        print(f"  WASM alloc() returned ptr = {ptr}")

        enc_wasm._wasm.free(ptr)
        print(f"  WASM free() OK")

        print("  [OK] WASM basic operations working.\n")
    except Exception as e:
        print("  [FAIL] WASM operations error:", e)
else:
    print("  Skipping WASM basic operations.\n")

print("\n========== DONE ==========\n")