Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanups. #43

Merged
merged 9 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 6 additions & 71 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
release:
types: [published]

env:
TOIT_VERSION: v2.0.0-alpha.144

jobs:
build:
strategy:
Expand All @@ -18,78 +21,10 @@ jobs:
with:
submodules: recursive

- name: Setup constants
shell: bash
run: |
TOIT_VERSION=v2.0.0-alpha.121
echo "TOIT_VERSION=$TOIT_VERSION" >> $GITHUB_ENV
export DOWNLOAD_DIR="${{ github.workspace }}/downloads"
echo "DOWNLOAD_DIR=$DOWNLOAD_DIR" >> $GITHUB_ENV
if [[ "$RUNNER_OS" = "Linux" ]]; then
TOIT_FILE=toit-linux.tar.gz
echo "TOIT_EXEC=$DOWNLOAD_DIR/toit/bin/toit.run" >> $GITHUB_ENV
echo "TPKG_EXEC=$DOWNLOAD_DIR/toit/bin/toit.pkg" >> $GITHUB_ENV
elif [[ "$RUNNER_OS" = "macOS" ]]; then
TOIT_FILE=toit-macos.tar.gz
echo "TOIT_EXEC=$DOWNLOAD_DIR/toit/bin/toit.run" >> $GITHUB_ENV
echo "TPKG_EXEC=$DOWNLOAD_DIR/toit/bin/toit.pkg" >> $GITHUB_ENV
elif [[ "$RUNNER_OS" = "Windows" ]]; then
TOIT_FILE=toit-windows.tar.gz
echo "TOIT_EXEC=$DOWNLOAD_DIR/toit/bin/toit.run.exe" >> $GITHUB_ENV
echo "TPKG_EXEC=$DOWNLOAD_DIR/toit/bin/toit.pkg.exe" >> $GITHUB_ENV
else
echo "UNSUPPORTED RUNNER: $RUNNER_OS"
exit 1
fi

if [[ $TOIT_VERSION = latest ]]; then
echo "TOIT_URL=https://github.com/toitlang/toit/releases/latest/download/$TOIT_FILE" >> $GITHUB_ENV
else
echo "TOIT_URL=https://github.com/toitlang/toit/releases/download/$TOIT_VERSION/$TOIT_FILE" >> $GITHUB_ENV
fi

# Fetch the dependencies. Different for each platform.
- name: Install dependencies - Linux
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install ninja-build
ninja --version
cmake --version
- name: Install dependencies - macOS
if: runner.os == 'macOS'
run: |
brew install ninja
ninja --version
cmake --version
- name: Install dependencies - Windows
if: runner.os == 'Windows'
run: |
choco install ninja
ninja --version
cmake --version

- uses: suisei-cn/[email protected]
name: Download Toit
- name: Install Toit SDK
uses: toitlang/action-setup@v1
with:
url: ${{ env.TOIT_URL }}
target: ${{ env.DOWNLOAD_DIR }}

- name: Extract Toit
shell: bash
run: |
cd "$DOWNLOAD_DIR"
tar x -f *.tar.gz

- name: Run cmake
shell: bash
run: |
make rebuild-cmake
cmake "-DTOIT_EXEC=$TOIT_EXEC" "-DTPKG_EXEC=$TPKG_EXEC" build

- name: Install packages
run: |
make install-pkgs
toit-version: ${{ env.TOIT_VERSION }}

- name: Test
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.swp
*.swo
.packages/
/build/
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

cmake_minimum_required(VERSION 3.22)

project(cli)
project(cli NONE)

enable_testing()
add_subdirectory(tests)
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ build/CMakeCache.txt:
$(MAKE) rebuild-cmake

install-pkgs: rebuild-cmake
(cd build && ninja install-pkgs)
cmake --build build --target install-pkgs

test: install-pkgs rebuild-cmake
(cd build && ninja check)
cmake --build build --target check

# We rebuild the cmake file all the time.
# We use "glob" in the cmakefile, and wouldn't otherwise notice if a new
# file (for example a test) was added or removed.
# It takes <1s on Linux to run cmake, so it doesn't hurt to run it frequently.
rebuild-cmake:
mkdir -p build
(cd build && cmake .. -G Ninja)
# We need to set a build type, otherwise cmake won't run nicely on Windows.
# The build-type is otherwise unused.
cmake -B build -DCMAKE_BUILD_TYPE=Debug

.PHONY: all test rebuild-cmake install-pkgs
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: png_display
description: A pseudo-pixel-display that writes PNG files.
environment:
sdk: ^2.0.0-alpha.121
sdk: ^2.0.0-alpha.144
dependencies:
pixel_display:
url: github.com/toitware/toit-pixel-display
Expand Down
13 changes: 6 additions & 7 deletions src/png-display.toit
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// Use of this source code is governed by an MIT-style license that can be
// found in the LICENSE file.

import binary show BIG-ENDIAN byte-swap-32
import io show BIG-ENDIAN Buffer ByteOrder
import bitmap show *
import bytes show Buffer
import crypto.crc show *
import monitor show Latch
import pixel-display show *
Expand Down Expand Up @@ -260,7 +259,7 @@ abstract class PngDriver_ extends AbstractDriver:
y_ = 0

task::
while data := compressor_.reader.read:
while data := compressor_.in.read:
compressed_.write data
if (not reproducible) and compressed_.size > 1900:
write-chunk writeable_ "IDAT" compressed_.bytes // Flush compressed pixel data.
Expand All @@ -273,19 +272,19 @@ abstract class PngDriver_ extends AbstractDriver:
several-color := flags & FLAG-SEVERAL-COLOR != 0
height.repeat: | y |
if y_ >= this.height: return
compressor_.write zero-byte // Adaptive scheme.
compressor_.out.write zero-byte // Adaptive scheme.
line-size := width-to-byte-width width
index := y * line-size
line := buffer[index..index + line-size]
if gray:
line = ByteArray line.size: line[it] ^ 0xff
else if several-color:
line = ByteArray line.size: min 6 line[it]
compressor_.write line
compressor_.out.write line
y_++

write-footer_:
compressor_.close
compressor_.out.close

// Wait for the reader task to finish.
done_.get
Expand All @@ -302,7 +301,7 @@ abstract class PngDriver_ extends AbstractDriver:

byte-swap_ ba/ByteArray -> ByteArray:
result := ba.copy
byte-swap-32 result
ByteOrder.swap-32 result
return result

/**
Expand Down
10 changes: 4 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

file(GLOB TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*-test.toit" "*-test-slow.toit")

set(TOIT_EXEC "toit.run" CACHE FILEPATH "The executable used to run the tests")
set(TPKG_EXEC "toit.pkg" CACHE FILEPATH "The executable used to install the packages")
set(TOIT_EXEC "toit.run${CMAKE_EXECUTABLE_SUFFIX}" CACHE FILEPATH "The executable used to run the tests")
set(TPKG_EXEC "toit.pkg${CMAKE_EXECUTABLE_SUFFIX}" CACHE FILEPATH "The executable used to install the packages")
set(TEST_TIMEOUT 40 CACHE STRING "The maximal amount of time each test is allowed to run")
set(SLOW_TEST_TIMEOUT 200 CACHE STRING "The maximal amount of time each slow test is allowed to run")

message("TPKG: ${TPKG_EXEC}")
add_custom_target(
"install-pkgs"
COMMAND "${TPKG_EXEC}" install
Expand All @@ -21,7 +20,7 @@ ProcessorCount(NUM_CPU)

add_custom_target(
check
COMMAND ${CMAKE_CTEST_COMMAND} -j${NUM_CPU} -T test --output-on-failure
COMMAND ${CMAKE_CTEST_COMMAND} -j${NUM_CPU} -T test --output-on-failure -C Debug
USES_TERMINAL
)

Expand All @@ -39,8 +38,7 @@ foreach(file ${TESTS})

add_test(
NAME "${test_name}"
COMMAND "sh" "tests/run-test.sh" "${TOIT_EXEC}" "${file}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..
COMMAND "${TOIT_EXEC}" "${CMAKE_CURRENT_SOURCE_DIR}/${file}"
)

if ("${file}" MATCHES "slow.toit")
Expand Down
32 changes: 32 additions & 0 deletions tests/gold.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2024 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the EXAMPLES_LICENSE file.

import expect show *
import fs
import host.os
import host.file
import io
import pixel-display show *
import png-display show *
import system

check-gold driver/PngDriver_ display/PixelDisplay:
test-path := system.program-path
test-dir := fs.dirname test-path
test-name := (fs.basename test-path).trim --right ".toit"
gold-path := fs.join test-dir "gold" "$(test-name).png"

stream := io.Buffer
// Writes a PNG file to the given filename.
// Only light compression is used, basically just run-length encoding
// of equal pixels. This is fast and reduces memory use.
write-to stream driver display --reproducible

actual := stream.bytes
if not file.is-file gold-path or os.env.get "UPDATE_GOLD":
print "Updating gold file: $gold-path"
file.write-contents --path=gold-path actual
else:
expected := file.read-contents gold-path
expect-equals expected actual
14 changes: 11 additions & 3 deletions tests/package.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sdk: ^2.0.0-alpha.121
sdk: ^2.0.0-alpha.144
prefixes:
font_x11_adobe: pkg-font-x11-adobe
fs: pkg-fs
host: pkg-host
pictogrammers_icons: toit-icons-pictogrammers
pixel_display: toit-pixel-display
Expand All @@ -16,11 +17,18 @@ packages:
name: font_x11_adobe
version: 0.1.0
hash: f844400722165252148f087cdf189abab0a47f3d
pkg-fs:
url: github.com/toitlang/pkg-fs
name: fs
version: 2.3.1
hash: 60836d4500317af2093d59d50c117d612c33f1fa
prefixes:
host: pkg-host
pkg-host:
url: github.com/toitlang/pkg-host
name: host
version: 1.7.1
hash: 6b017ad10563263080bba6acde387ceebc13270b
version: 1.15.3
hash: 62393e8522b77eafbafe60b9817935266117daf6
toit-font-google-100dpi-roboto:
url: github.com/toitware/toit-font-google-100dpi-roboto
name: roboto
Expand Down
3 changes: 3 additions & 0 deletions tests/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ dependencies:
font_x11_adobe:
url: github.com/toitlang/pkg-font-x11-adobe
version: ^0.1.0
fs:
url: github.com/toitlang/pkg-fs
version: ^2.3.1
host:
url: github.com/toitlang/pkg-host
version: ^1.5.1
Expand Down
15 changes: 0 additions & 15 deletions tests/run-test.sh

This file was deleted.

7 changes: 2 additions & 5 deletions tests/simple-3-color-test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import pixel-display.style show *
import pixel-display.three-color show WHITE BLACK RED
import font show *

import .write-file
import .gold

main args:
driver := ThreeColorPngDriver 104 50
Expand All @@ -22,7 +22,4 @@ main args:
display.add (Label --style=style --x=20 --y=30 --text="Toit")
display.add (Label --style=red --x=60 --y=30 --text="Red")

filename := args.size == 0 ? "-" : args[0]

print "Writing $filename"
write-file filename driver display
check-gold driver display
7 changes: 2 additions & 5 deletions tests/simple-bw-test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import pixel-display.style show *
import pixel-display.two-color show WHITE BLACK
import font show *

import .write-file
import .gold

main args:
driver := TwoColorPngDriver 104 50
Expand All @@ -24,7 +24,4 @@ main args:
display.add (Div --style=black --x=15 --y=15 --w=40 --h=30)
display.add (Label --style=white --x=20 --y=30 --text="Toit")

filename := args.size == 0 ? "-" : args[0]

print "Writing $filename"
write-file filename driver display
check-gold driver display
7 changes: 2 additions & 5 deletions tests/simple-color-test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import pixel-display.style show *
import pixel-display.true-color show *
import font show *

import .write-file
import .gold

main args:
driver := TrueColorPngDriver 104 50
Expand All @@ -21,7 +21,4 @@ main args:
display.add (Label --style=style --x=20 --y=30 --text="Toit")
display.add (Label --style=blue --x=50 --y=30 --text="50%")

filename := args.size == 0 ? "-" : args[0]

print "Writing $filename"
write-file filename driver display
check-gold driver display
7 changes: 2 additions & 5 deletions tests/simple-gray-test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import pixel-display.four-gray show WHITE BLACK LIGHT-GRAY DARK-GRAY
import pixel-display.style show *
import font show *

import .write-file
import .gold

main args:
driver := FourGrayPngDriver 104 50
Expand All @@ -25,7 +25,4 @@ main args:
display.add (Label --style=light-gray --x=35 --y=20 --text="Light gray")
display.add (Label --style=dark-gray --x=35 --y=40 --text="Dark gray")

filename := args.size == 0 ? "-" : args[0]

print "Writing $filename"
write-file filename driver display
check-gold driver display
Loading