add automation scripts.

This commit is contained in:
Jordan 2024-03-11 10:42:48 -07:00
parent b3cd0316b7
commit 29483913d6
8 changed files with 154 additions and 28 deletions

View File

@ -0,0 +1,14 @@
import 'dart:ffi';
import 'package:archimedes_mobile_lib/dynloader.dart';
import 'archimedes_mobile_lib_bindings_generated.dart';
final _dylib = getArchimedesCLib();
final ArchimedesMobileLibBindings _bindings =
ArchimedesMobileLibBindings(_dylib);
int getImageData(Pointer<Frame> frame, Pointer<UnsignedChar> data) =>
_bindings.archimedes_get_image_data(frame, data);
Pointer<Frame> newFrame(
Pointer<Uint8> data, int dataLen, int w, int h, int depth) =>
_bindings.new_frame_from_data(data, dataLen, w, h, depth);

View File

@ -4,43 +4,19 @@ import 'dart:io';
import 'dart:typed_data';
// import 'dart:isolate';
// import 'dart:ui';
import 'package:archimedes_mobile_lib/archimedes_c_shim.dart';
import 'package:archimedes_mobile_lib/dynloader.dart';
import "package:ffi/ffi.dart";
import "package:path/path.dart" show dirname, join;
import 'dart:io' show Platform;
import 'archimedes_mobile_lib_bindings_generated.dart';
const String _libName = 'archimedes_mobile_lib';
final here = dirname(Platform.script.path);
final build = join(dirname(here), "build");
/// The dynamic library in which the symbols for [ArchimedesMobileLibBindings] can be found.
final DynamicLibrary _dylib = () {
if (Platform.isMacOS || Platform.isIOS) {
return DynamicLibrary.open(join(build, '$_libName.framework', _libName));
}
if (Platform.isAndroid || Platform.isLinux) {
return DynamicLibrary.open(join(build, 'lib$_libName.so'));
}
if (Platform.isWindows) {
return DynamicLibrary.open(join('$_libName.dll'));
}
throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
}();
/// The bindings to the native functions in [_dylib].
final ArchimedesMobileLibBindings _bindings =
ArchimedesMobileLibBindings(_dylib);
int getImageData(Pointer<Frame> frame, Pointer<UnsignedChar> data) =>
_bindings.archimedes_get_image_data(frame, data);
Pointer<Frame> newFrame(
Pointer<Uint8> data, int dataLen, int w, int h, int depth) =>
_bindings.new_frame_from_data(data, dataLen, w, h, depth);
final DynamicLibrary _dylib = getArchimedesCLib();
void main(List<String> arguments) {
final assets = join(dirname(here), "assets");
final assets = join(HERE.parent.path, "assets");
final testFrames = join(assets, "test", "frames");
final firstFrame = join(testFrames, "0001.png");
final f = File(firstFrame);

25
lib/dynloader.dart Normal file
View File

@ -0,0 +1,25 @@
import 'dart:ffi';
import 'dart:io';
import "package:ffi/ffi.dart";
import "package:path/path.dart" show dirname, join;
import 'dart:io' show Platform;
import 'archimedes_mobile_lib_bindings_generated.dart';
const String _libName = 'archimedes_mobile_lib';
final HERE = File(String.fromEnvironment("CURRENT_EXEC_DIR",
defaultValue: (File(Platform.script.path).parent.absolute.path)));
final BUILD_DIR = File(join(HERE.path, "build"));
DynamicLibrary getArchimedesCLib() {
if (Platform.isMacOS || Platform.isIOS) {
return DynamicLibrary.open(
join(BUILD_DIR.path, '$_libName.framework', _libName));
}
if (Platform.isAndroid || Platform.isLinux) {
return DynamicLibrary.open(join(BUILD_DIR.path, 'lib$_libName.so'));
}
if (Platform.isWindows) {
return DynamicLibrary.open(join(BUILD_DIR.path, '$_libName.dll'));
}
throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
}

50
lib/util.dart Normal file
View File

@ -0,0 +1,50 @@
import 'dart:collection';
import 'dart:ffi';
import 'dart:io';
import "package:ffi/ffi.dart";
class Uint8FlexList extends ListBase<Uint8> {
final List<Uint8> _list = [];
Uint8FlexList();
late Pointer<Uint8> pointer;
@override
Uint8 operator [](int index) => _list[index];
set list(List<Uint8> l) {
_list.removeWhere((element) => true);
_list.addAll(l);
pointer = calloc<Uint8>(l.length);
_list.forEach((element) {
pointer[_list.indexOf(element)] = element as int;
});
}
@override
void operator []=(int index, Uint8 value) {
_list[index] = value;
pointer[index] = value as int;
}
@override
int get length => _list.length;
@override
set length(int newLength) {
throw Error();
}
static fromList(List<Uint8> l) {
final l2 = Uint8FlexList();
}
}
Pointer<Uint8> readUint8Ptr(File file) {
final l = file.readAsBytesSync().cast();
final dataPointer = calloc<Uint8>(l.length);
for (int i = 0; i < l.length; ++i) {
dataPointer[i] = l[i];
}
return dataPointer;
}

View File

@ -8,6 +8,8 @@ environment:
flutter: '>=3.3.0'
dependencies:
test:
ffi:
flutter:
sdk: flutter
plugin_platform_interface: ^2.0.2

17
scripts/darttest.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do
DIR=$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE
done
DIR=$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)
ROOT_DIR=$(realpath ${DIR}..)
LIB_DIR=$(realpath ${DIR}/../lib)
TEST_DIR=$(realpath ${DIR}/../tests)
printf "\033c"
dart --define=CURRENT_EXEC_DIR="${ROOT_DIR}" test ${TEST_DIR}

15
scripts/watch_darttest.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do
DIR=$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE
done
DIR=$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)
ROOT_DIR=$(realpath ${DIR}/..)
LIB_DIR=$(realpath ${DIR}/../lib)
TEST_DIR=$(realpath ${DIR}/../tests)
cd ${ROOT_DIR} && find ${LIB_DIR} ${TEST_DIR} -iname '*.dart' | entr -r ${DIR}/darttest.sh

27
tests/main_test.dart Normal file
View File

@ -0,0 +1,27 @@
import 'dart:ffi';
import 'dart:io';
import 'package:archimedes_mobile_lib/archimedes_c_shim.dart';
import 'package:archimedes_mobile_lib/dynloader.dart';
import 'package:archimedes_mobile_lib/util.dart';
import 'package:ffi/ffi.dart';
import 'package:test/test.dart';
import "package:path/path.dart" show dirname, join;
final assets = join(HERE.parent.path, "assets");
final testFrames = join(assets, "test", "frames");
final firstFrame = join(testFrames, "0001.png");
void main() {
group('Unit Tests', () {
setUp(() {});
tearDown(() {
// Tear down code
});
test('newFrame', () {
Pointer<Uint8> frameData = readUint8Ptr(File(firstFrame));
// newFrame(frameData, fData.length, 768, 768, 1204);
});
});
}