|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# SPDX-License-Identifier: BSD-2-Clause |
| 4 | +# SPDX-FileCopyrightText: Copyright (c) 2025 RISC-V International |
| 5 | + |
| 6 | +# Container tests script for riscv-unified-db |
| 7 | + |
| 8 | +set -e |
| 9 | +set -o pipefail |
| 10 | + |
| 11 | +echo "Running container tests..." |
| 12 | + |
| 13 | +# Test 1: Check if we can build the container |
| 14 | +echo "Test 1: Building container..." |
| 15 | +docker build -t riscv-unified-db-test .devcontainer/ |
| 16 | + |
| 17 | +# Test 2: Check if we can run basic commands in the container |
| 18 | +echo "Test 2: Running basic commands in container..." |
| 19 | +docker run --rm riscv-unified-db-test ruby --version |
| 20 | +docker run --rm riscv-unified-db-test python3 --version |
| 21 | +docker run --rm riscv-unified-db-test npm --version |
| 22 | + |
| 23 | +# Test 3: Check if we can install Python packages in a virtual environment |
| 24 | +echo "Test 3: Installing Python packages in virtual environment..." |
| 25 | +docker run --rm -v "$(pwd)":/workspace riscv-unified-db-test bash -c \ |
| 26 | +"cd /workspace && \ |
| 27 | +python3 -m venv .venv && \ |
| 28 | +source .venv/bin/activate && \ |
| 29 | +pip install --quiet -r requirements.txt && \ |
| 30 | +pip list && \ |
| 31 | +deactivate" |
| 32 | + |
| 33 | +# Test 4: Check if we can install Python packages with --break-system-packages flag |
| 34 | +echo "Test 4: Installing Python packages with --break-system-packages flag..." |
| 35 | +docker run --rm -v "$(pwd)":/workspace riscv-unified-db-test bash -c \ |
| 36 | +"cd /workspace && \ |
| 37 | +pip3 install --break-system-packages --quiet -r requirements.txt && \ |
| 38 | +pip3 list" |
| 39 | + |
| 40 | +# Test 5: Check if we can install gems |
| 41 | +echo "Test 5: Installing gems..." |
| 42 | +docker run --rm riscv-unified-db-test gem list bundler |
| 43 | + |
| 44 | +# Test 6: Check if we can run rake tasks |
| 45 | +echo "Test 6: Running rake tasks..." |
| 46 | +docker run --rm -v "$(pwd)":/workspace riscv-unified-db-test rake --version |
| 47 | + |
| 48 | +# Test 7: Check non-root user exists |
| 49 | +echo "Test 7: Checking non-root user..." |
| 50 | +docker run --rm riscv-unified-db-test id -u vscode |
| 51 | + |
| 52 | +# Test 8: Proxy configuration test |
| 53 | +echo "Test 8: Checking proxy configuration..." |
| 54 | +docker run --rm \ |
| 55 | +-e http_proxy=http://test.proxy:3128 \ |
| 56 | +-e https_proxy=http://test.proxy:3128 \ |
| 57 | +riscv-unified-db-test bash -c "env | grep -i proxy" |
| 58 | + |
| 59 | +# Test 9: Check apt proxy configuration |
| 60 | +echo "Test 9: Checking apt proxy configuration..." |
| 61 | +docker run --rm \ |
| 62 | +-e http_proxy=http://test.proxy:3128 \ |
| 63 | +riscv-unified-db-test bash -c \ |
| 64 | +"if [ -f /etc/apt/apt.conf.d/01proxy ]; then cat /etc/apt/apt.conf.d/01proxy; else echo 'No apt proxy configuration found'; fi" |
| 65 | + |
| 66 | +# Test 10: Check pip proxy configuration |
| 67 | +echo "Test 10: Checking pip proxy configuration..." |
| 68 | +docker run --rm \ |
| 69 | +-e http_proxy=http://test.proxy:3128 \ |
| 70 | +riscv-unified-db-test bash -c \ |
| 71 | +"if [ -f /etc/pip.conf ]; then cat /etc/pip.conf; else echo 'No pip proxy configuration found'; fi" |
| 72 | + |
| 73 | +# Test 11: Check npm proxy configuration |
| 74 | +echo "Test 11: Checking npm proxy configuration..." |
| 75 | +docker run --rm \ |
| 76 | +-e http_proxy=http://test.proxy:3128 \ |
| 77 | +riscv-unified-db-test bash -c \ |
| 78 | +"npm config get proxy 2>/dev/null || echo 'No npm proxy configured'" |
| 79 | + |
| 80 | +# Test 12: Check bundler proxy configuration |
| 81 | +echo "Test 12: Checking bundler proxy configuration..." |
| 82 | +docker run --rm \ |
| 83 | +-e http_proxy=http://test.proxy:3128 \ |
| 84 | +riscv-unified-db-test bash -c \ |
| 85 | +"bundle config http_proxy 2>/dev/null || echo 'No bundler proxy configured'" |
| 86 | + |
| 87 | +# Test 13: Check pre-created virtual environment |
| 88 | +echo "Test 13: Checking pre-created virtual environment..." |
| 89 | +docker run --rm riscv-unified-db-test bash -c \ |
| 90 | +"ls -la /opt/venv/bin/python && \ |
| 91 | +/opt/venv/bin/python --version" |
| 92 | + |
| 93 | +# Cleanup |
| 94 | +echo "Cleaning up..." |
| 95 | +docker rmi -f riscv-unified-db-test > /dev/null 2>&1 || true |
| 96 | + |
| 97 | +echo "All container tests passed!" |
0 commit comments