Skip to content

Commit

Permalink
test: add basic test setup to reproduce current tests
Browse files Browse the repository at this point in the history
Problem: we need to reproduce tests currently in flux-sched here.
Solution: separate the tests (modules and binary) in a Makefile,
also adding support for make build to build the binary (and assert
that the fluxmodule and fluxcli are functioning as expected).

Signed-off-by: vsoch <[email protected]>
  • Loading branch information
vsoch committed Feb 16, 2024
1 parent c1f9c9a commit 1cc5fc0
Show file tree
Hide file tree
Showing 13 changed files with 3,708 additions and 5 deletions.
35 changes: 35 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM fluxrm/flux-sched:bookworm

LABEL maintainer="Vanessasaurus <@vsoch>"

# Match the default user id for a single system so we aren't root
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=1000
ENV USERNAME=${USERNAME}
ENV USER_UID=${USER_UID}
ENV USER_GID=${USER_GID}
USER root
RUN apt-get update && apt-get install -y less

# Install Go 19 (we should update this)
RUN wget https://go.dev/dl/go1.19.10.linux-amd64.tar.gz && tar -xvf go1.19.10.linux-amd64.tar.gz && \
mv go /usr/local && rm go1.19.10.linux-amd64.tar.gz
ENV PATH=$PATH:/usr/local/go/bin:/home/vscode/go/bin

RUN git clone https://github.com/flux-framework/flux-sched /opt/flux-sched && \
cd /opt/flux-sched && \
git fetch && \
export FLUX_SCHED_VERSION=0.58.0 && \
./autogen.sh && \
./configure --prefix=/usr && \
make && make install

# Add the group and user that match our ids
RUN groupadd -g ${USER_GID} ${USERNAME} && \
adduser --disabled-password --uid ${USER_UID} --gid ${USER_GID} --gecos "" ${USERNAME} && \
echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers

USER $USERNAME
# Assuming installing to /usr/local
ENV LD_LIBRARY_PATH=/usr/lib:/usr/lib/flux:/usr/local/lib
18 changes: 18 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Fluxion Go",
"dockerFile": "Dockerfile",
"context": "../",

"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "bash"
},
"extensions": [
"ms-vscode.cmake-tools",
"golang.go"
]
}
},
"postStartCommand": "git config --global --add safe.directory /workspaces/fluxion-go"
}
38 changes: 38 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: test fluxion-go

# This will be expanded for more robust testing
# right now we build and run the main test command
# and test the package "types" directory

on:
pull_request: []

jobs:
test:
name: Test fluxion-go
runs-on: ubuntu-latest

# TODO add more configurations
strategy:
fail-fast: false
matrix:
test: [["fluxrm/flux-sched:bookworm"]]

container:
image: ${{ matrix.test[0] }}
options: --user root
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ^1.19
# TODO: do we want this to be for different versions? Need to coincide with container bases
- name: flux-sched Clone
run: git clone https://github.com/flux-framework/flux-sched /opt/flux-sched
- name: Build
run: make build
- name: Test Binary
run: make test-binary
- name: Test Modules
run: make test-modules
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor
bin
55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
HERE ?= $(shell pwd)
LOCALBIN ?= $(shell pwd)/bin
JGF ?= $(HERE)/cmd/test/data/tiny.json
JOBSPECS ?= $(HERE)/cmd/test/data/jobspecs

# This assumes a build in the .devcontainer Dockerfile environment
FLUX_SCHED_ROOT ?= /opt/flux-sched
INSTALL_PREFIX ?= /usr
COMMONENVVAR=GOOS=$(shell uname -s | tr A-Z a-z)

BUILDENVVAR=CGO_CFLAGS="-I${FLUX_SCHED_ROOT} -I${FLUX_SCHED_ROOT}/resource/reapi/bindings/c" CGO_LDFLAGS="-L${INSTALL_PREFIX}/lib -L${INSTALL_PREFIX}/lib/flux -L${FLUX_SCHED_ROOT}/resource/reapi/bindings -lreapi_cli -lflux-idset -lstdc++ -lczmq -ljansson -lhwloc -lboost_system -lflux-hostlist -lboost_graph -lyaml-cpp"
# BUILDENVAR=CGO_CFLAGS="${CGO_CFLAGS}" CGO_LDFLAGS='${CGO_LIBRARY_FLAGS}' go build -ldflags '-w'


.PHONY: all
all: build

.PHONY: test
test: test-binary test-modules

.PHONY: test-modules
test-modules:
go test -v ./pkg/types

.PHONY: test-binary
test-binary:
$(LOCALBIN)/test --jgf=$(JGF) --jobspec=$(JOBSPECS)/test001.yaml

# test001_desc="match allocate 1 slot: 1 socket: 1 core (pol=default)"
# test_expect_success "${test001_desc}" '
# ${main} --jgf=${jgf} --jobspec=${jobspec1} > 001.R.out &&
# sed -i -E "s/, 0\.[0-9]+//g" 001.R.out &&
# test_cmp 001.R.out ${exp_dir}/001.R.out
#'

#test002_desc="match allocate 2 slots: 2 sockets: 5 cores 1 gpu 6 memory"
#test_expect_success "${test002_desc}" '
# ${main} --jgf=${jgf} --jobspec=${jobspec2} > 002.R.out &&
# sed -i -E "s/, 0\.[0-9]+//g" 002.R.out &&
# test_cmp 002.R.out ${exp_dir}/002.R.out
#'

.PHONY: $(LOCALBIN)
$(LOCALBIN):
mkdir -p $(LOCALBIN)

# This serves as a single test file to build a dummy main to test
.PHONY: build $(LOCALBIN)
build:
mkdir -p $(LOCALBIN)
$(COMMONENVVAR) $(BUILDENVVAR) go build -ldflags '-w' -o $(LOCALBIN)/test cmd/test/test.go

.PHONY: clean
clean:
rm -rf $(LOCALBIN)/test
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@
Fluxion Go are the Go bindings for the flux scheduler [flux-framework.org/flux-sched](https://github.com/flux-framework.org/flux-sched) that we call "fluxion." You can read more about the project there. In short, you might want to use these bindings if you're interested in integrating the flux scheduler logic (graph-based, hierarchical scheduling) into your Go applications.

## Usage

Currently, you can build in the [Development Container](.devcontainer) in VSCode and then flux-sched will be installed to `/usr` and header files (.h) available at `/opt/flux-sched`. You can build the test suite as follows:

```bash
make
```
```console
mkdir -p /workspaces/fluxion-go/bin
GOOS=linux CGO_CFLAGS="-I/opt/flux-sched -I/opt/flux-sched/resource/reapi/bindings/c" CGO_LDFLAGS="-L/usr/lib -L/usr/lib/flux -L/opt/flux-sched/resource/reapi/bindings -lreapi_cli -lflux-idset -lstdc++ -lczmq -ljansson -lhwloc -lboost_system -lflux-hostlist -lboost_graph -lyaml-cpp" go build -ldflags '-w' -o /workspaces/fluxion-go/bin/test cmd/test/test.go
```

If you need to customize the flux install prefix or the location (root) of the flux-sched repository (with header files):

```bash
FLUX_SCHED_ROOT=/home/path/flux-sched INSTALL_PREFIX=/usr/local make
```

Here is how to run tests:

```bash
# run all tests
make test

# run binary test (e.g., build main and run)
make test-binary

# run go native tests
make test-modules
```

More work and updates will be coming soon.

#### License

SPDX-License-Identifier: LGPL-3.0
Expand Down
30 changes: 30 additions & 0 deletions cmd/test/data/jobspecs/test001.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: 9999
resources:
- type: cluster
count: 1
with:
- type: rack
count: 1
with:
- type: node
count: 1
with:
- type: slot
count: 1
label: default
with:
- type: socket
count: 1
with:
- type: core
count: 1
# a comment
attributes:
system:
duration: 3600
tasks:
- command: [ "app" ]
slot: default
count:
per_slot: 1

Loading

0 comments on commit 1cc5fc0

Please sign in to comment.