File: test_mip_local_install.sh

package info (click to toggle)
micropython 1.26.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 50,196 kB
  • sloc: ansic: 324,551; python: 63,215; xml: 4,241; makefile: 3,618; sh: 1,586; javascript: 754; asm: 723; cpp: 83; exp: 11; pascal: 6
file content (67 lines) | stat: -rwxr-xr-x 1,918 bytes parent folder | download | duplicates (2)
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
#!/bin/bash

# This test the "mpremote mip install" from local files. It creates a package
# and "mip installs" it into a ramdisk. The package is then imported and
# executed. The package is a simple "Hello, world!" example.

set -e

PACKAGE=mip_example
PACKAGE_DIR=${TMP}/example
MODULE_DIR=${PACKAGE_DIR}/${PACKAGE}

target=/__ramdisk
block_size=512
num_blocks=50

# Create the smallest permissible ramdisk.
cat << EOF > "${TMP}/ramdisk.py"
class RAMBlockDev:
    def __init__(self, block_size, num_blocks):
        self.block_size = block_size
        self.data = bytearray(block_size * num_blocks)

    def readblocks(self, block_num, buf):
        for i in range(len(buf)):
            buf[i] = self.data[block_num * self.block_size + i]

    def writeblocks(self, block_num, buf):
        for i in range(len(buf)):
            self.data[block_num * self.block_size + i] = buf[i]

    def ioctl(self, op, arg):
        if op == 4: # get number of blocks
            return len(self.data) // self.block_size
        if op == 5: # get block size
            return self.block_size

import os

bdev = RAMBlockDev(${block_size}, ${num_blocks})
os.VfsFat.mkfs(bdev)
os.mount(bdev, '${target}')
EOF

echo ----- Setup
mkdir -p ${MODULE_DIR}
echo "def hello(): print('Hello, world!')" > ${MODULE_DIR}/hello.py
echo "from .hello import hello" > ${MODULE_DIR}/__init__.py
cat > ${PACKAGE_DIR}/package.json <<EOF
{
    "urls": [
        ["${PACKAGE}/__init__.py", "${PACKAGE}/__init__.py"],
        ["${PACKAGE}/hello.py", "${PACKAGE}/hello.py"]
    ],
    "version": "0.2"
}
EOF

$MPREMOTE run "${TMP}/ramdisk.py"
$MPREMOTE resume mkdir ${target}/lib
echo
echo ---- Install package
$MPREMOTE resume mip install --target=${target}/lib ${PACKAGE_DIR}/package.json
echo
echo ---- Test package
$MPREMOTE resume exec "import sys; sys.path.append(\"${target}/lib\")"
$MPREMOTE resume exec "import ${PACKAGE}; ${PACKAGE}.hello()"