Skip to content

Commit

Permalink
refactor: move tests to top-level out of the devcontainer folder (#624)
Browse files Browse the repository at this point in the history
* refactor: move tests to top-level out of the devcontainer folder

* chore: fix rust tests

* chore: fix Sonar findings

* refactor: share workspace between integration and e2e tests

* chore: move tests after merge

* fix: correct path to end-to-end tests

* test: store playwright artifacts

* test: press enter on searchbox

* test: press enter on page

* test: reduce changes to test code

* chore: fix Sonar findings

* chore: temporarily disable test
  • Loading branch information
rjaegers authored Nov 6, 2024
1 parent 252fab6 commit 92ea3e3
Show file tree
Hide file tree
Showing 72 changed files with 110 additions and 125 deletions.
8 changes: 6 additions & 2 deletions .devcontainer/cpp-test/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"image": "ghcr.io/philips-software/amp-devcontainer-cpp:${localEnv:IMAGE_VERSION}",
"workspaceFolder": "/workspaces/amp-devcontainer/.devcontainer/cpp/e2e/workspace",
"workspaceFolder": "/workspaces/amp-devcontainer/test/cpp/workspace",
"customizations": {
"vscode": {
"settings": {
"cmake.automaticReconfigure": false
"cmake.automaticReconfigure": false,
"cmake.configureOnOpen": false,
"cmake.ctest.testExplorerIntegrationEnabled": false,
"cmake.enableAutomaticKitScan": false,
"cmake.showOptionsMovedNotification": false
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/cpp/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"customizations": {
"vscode": {
"settings": {
"cucumberautocomplete.steps": [".devcontainer/cpp/e2e/features/steps/*.steps.ts"],
"cucumberautocomplete.steps": ["test/cpp/features/steps/*.steps.ts"],
"cucumberautocomplete.strictGherkinCompletion": false,
"cucumberautocomplete.strictGherkinValidation": false,
"cucumberautocomplete.smartSnippets": true,
Expand Down
5 changes: 0 additions & 5 deletions .devcontainer/cpp/e2e/workspace/CMakeLists.txt

This file was deleted.

40 changes: 0 additions & 40 deletions .devcontainer/cpp/e2e/workspace/CMakePresets.json

This file was deleted.

7 changes: 0 additions & 7 deletions .devcontainer/cpp/e2e/workspace/formatted.cpp

This file was deleted.

12 changes: 0 additions & 12 deletions .devcontainer/cpp/e2e/workspace/main.cpp

This file was deleted.

8 changes: 0 additions & 8 deletions .devcontainer/cpp/e2e/workspace/unformatted.cpp

This file was deleted.

6 changes: 0 additions & 6 deletions .devcontainer/cpp/test/gcc-arm-none-eabi/main.cpp

This file was deleted.

12 changes: 0 additions & 12 deletions .devcontainer/cpp/test/sanitizers/threadsan.cpp

This file was deleted.

4 changes: 4 additions & 0 deletions .devcontainer/rust-test/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"image": "ghcr.io/philips-software/amp-devcontainer-rust:${localEnv:IMAGE_VERSION}",
"workspaceFolder": "/workspaces/amp-devcontainer/test/rust/workspace"
}
9 changes: 8 additions & 1 deletion .github/workflows/acceptance-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ jobs:
env:
GH_TOKEN: ${{ secrets.TEST_GITHUB_TOKEN }}
HEAD_REF: ${{ github.head_ref }}
- run: cd .devcontainer/${{ inputs.flavor }}/e2e && npm test
- run: cd test/${{ inputs.flavor }}/features && npm test
env:
GITHUB_USER: ${{ secrets.TEST_GITHUB_USER }}
GITHUB_PASSWORD: ${{ secrets.TEST_GITHUB_PASSWORD }}
GITHUB_TOTP_SECRET: ${{ secrets.TEST_GITHUB_TOTP_SECRET }}
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
if: always()
with:
name: playwright-artifacts
path: |
test-results/
retention-days: 10
- run: |
set -Eeuo pipefail
gh codespace delete --force --codespace "$CODESPACE_NAME"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Run Tests
run: |
set -Eeuo pipefail
docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock --mount type=bind,src="${{ github.workspace }}/.devcontainer/${{ matrix.flavor }}/test",dst=/ws -w /ws ${{ github.repository }}-${{ matrix.flavor }}:test bats --formatter junit testsuite.bats | tee test-report-${{ matrix.flavor }}.xml
docker run --rm --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock --mount type=bind,src="${{ github.workspace }}/test/${{ matrix.flavor }}",dst=/ws -w /ws ${{ github.repository }}-${{ matrix.flavor }}:test bats --formatter junit integration-tests.bats | tee test-report-${{ matrix.flavor }}.xml
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
if: always()
with:
Expand Down
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"version": "2.0.0",
"tasks": [
{
"label": "Run Tests",
"label": "Run Integration Tests",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
},
"command": "bats",
"args": ["testsuite.bats"],
"args": ["integration-tests.bats"],
"options": {
"cwd": "${workspaceFolder}/.devcontainer/${env:CONTAINER_FLAVOR}/test"
"cwd": "${workspaceFolder}/test/${env:CONTAINER_FLAVOR}"
},
"presentation": {
"reveal": "always",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Compile source code into working software

As a developer
In order to generate working software
To generate working software
Source code needs to be compiled successfully

Scenario: Compile valid source code into working software targeting the host architecture
Expand All @@ -13,6 +13,7 @@ Feature: Compile source code into working software
- running tests on the host
- building plug-ins, extensions, code generators, or other additional tools that need to run on the host

Given the default build configuration is selected
When the configuration "host" is built
Given build configuration "gcc" is selected
And build preset "gcc" is selected
When the selected target is built
Then the output should contain "Build finished with exit code 0"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Page } from '@playwright/test';
import * as OTPAuth from 'otpauth';
import { STORAGE_STATE } from '../../playwright.config';
import { STORAGE_STATE } from '../playwright.config';

export class AuthenticationPage {
readonly page: Page;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test, expect, type Page, type Locator } from '@playwright/test';
import path from 'path';

type CommandAndPrompt = {
command: string,
Expand Down Expand Up @@ -97,23 +98,48 @@ export class CodespacePage {
}

async openFileInEditor(name: string) {
await this.page.getByRole('treeitem', { name: name }).locator('a').click();
await expect(this.page.locator('[id="workbench.parts.editor"]')).toContainText(name);
await this.page.keyboard.press('Control+P');
const searchBox = this.page.getByPlaceholder('Search files by name');
await expect(searchBox).toBeVisible();

await searchBox.fill(name);
await this.page.keyboard.press('Enter');
await expect(this.page.locator('[id="workbench.parts.editor"]')).toContainText(path.basename(name));
}

async openCppFileInEditor(name: string) {
await this.openFileInEditor(name);
await expect(this.page.locator('[id="llvm-vs-code-extensions.vscode-clangd"]')).toContainText('clangd: idle', { timeout: 1 * 60 * 1000 });
}

async formatDocument() {
await this.executeFromCommandPalette({ command: 'Format Document' });
async openDocument(name: string) {
const fileExtension = path.extname(name).slice(1);

if (fileExtension === 'cpp') {
await this.openCppFileInEditor(name);
} else {
await this.openFileInEditor(name);
}
}

async saveDocument() {
await this.page.keyboard.press('Control+S');
}

async formatDocument() {
await this.executeFromCommandPalette({ command: 'Format Document' });
}

async selectBuildConfiguration(configuration: string) {
await this.executeFromCommandPalette({ command: 'CMake: Select Configure Preset' });
await this.page.getByRole('option', { name: configuration, exact: true }).locator('a').click();
}

async selectBuildPreset(preset: string) {
await this.executeFromCommandPalette({ command: 'CMake: Select Build Preset' });
await this.page.getByRole('option', { name: preset, exact: true }).locator('a').click();
}

async buildSelectedTarget() {
await this.page.getByRole('button', { name: 'Build the selected target' }).click();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require('dotenv').config({ path: path.join(__dirname, '..', '..', '..', '.env')
export const STORAGE_STATE = path.join(__dirname, 'playwright/.auth/user.json');

const testDir = defineBddConfig({
features: "features/*.feature",
steps: ["features/steps/*.ts"],
features: "*.feature",
steps: ["steps/*.ts"],
});

export default defineConfig({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Feature: Analyze source code using static and dynamic analysis
To maintain consistent, high-quality and bug-free code
Source code needs to be statically and dynamically analyzed

@fixme
Scenario: Format source code according to a formatting style

Given the file "unformatted.cpp" is opened in the editor
Given the file "clang-tools/unformatted.cpp" is opened in the editor
When the active document is formatted
And the active document is saved
Then the contents of "unformatted.cpp" should match the contents of "formatted.cpp"
Then the contents of "clang-tools/unformatted.cpp" should match the contents of "clang-tools/formatted.cpp"
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import { expect } from "@playwright/test";
import { Given, When, Then } from "./fixtures";
import * as path from 'path';

Given("the default build configuration is selected", async () => {
// No-op
Given("build configuration {string} is selected", async ({ codespacePage }, configuration: string) => {
await codespacePage.selectBuildConfiguration(configuration);
});

Given("the file {string} is opened in the editor", async ({ codespacePage }, file: string) => {
const fileExtension = path.extname(file).slice(1);
Given("build preset {string} is selected", async ({ codespacePage }, preset: string) => {
await codespacePage.selectBuildPreset(preset);
});

switch (fileExtension) {
case 'cpp':
await codespacePage.openCppFileInEditor(file);
break;
default:
await codespacePage.openFileInEditor(file);
}
Given("the file {string} is opened in the editor", async ({ codespacePage }, file: string) => {
await codespacePage.openDocument(file);
});

When("the configuration {string} is built", async ({ codespacePage }, configuration: string) => {
await codespacePage.page.getByRole('button', { name: 'Build the selected target' }).click();
await codespacePage.page.getByLabel(configuration).locator('a').click();
When("the selected target is built", async ({ codespacePage }) => {
await codespacePage.buildSelectedTarget();
});

When("the active document is formatted", async ({ codespacePage }) => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ teardown_file() {
setup() {
load '/usr/local/bats-support/load'
load '/usr/local/bats-assert/load'

pushd workspace
}

teardown() {
rm -rf build crash-* $(conan config home)/p

popd
}

@test "valid code input should result in working executable using host compiler" {
Expand Down Expand Up @@ -220,4 +224,8 @@ function build_and_run_with_sanitizers() {
run build/${PRESET}/sanitizers/test-ubsan
assert_failure
assert_output --partial "runtime error: load of null pointer"

run build/${PRESET}/sanitizers/test-threadsan
assert_failure
assert_output --partial "ThreadSanitizer: data race"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.30)
project(devcontainer-test LANGUAGES ASM C CXX)

set(CMAKE_CXX_STANDARD 20)

include(CTest)
include(GoogleTest)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions test/cpp/workspace/clang-tools/formatted.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int main() {}
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions test/cpp/workspace/gcc-arm-none-eabi/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[[noreturn]] void _exit(int)
{
while (true);
}

int main() {}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions test/cpp/workspace/sanitizers/threadsan.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <ranges>
#include <thread>
#include <vector>

int main()
{
std::vector<std::jthread> threads;
int counter = 0;

for (auto i : std::ranges::iota_view(0, 10))
threads.emplace_back(std::jthread([&counter] {
for (auto j : std::ranges::iota_view(0, 1000))
++counter;
}));

return counter;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ bats_require_minimum_version 1.5.0
setup() {
load '/usr/local/bats-support/load'
load '/usr/local/bats-assert/load'

pushd workspace
}

teardown() {
rm -rf build ./**/target ./**/default*.prof* ./**/mutants.out

popd
}

@test "valid code input should result in working executable targeting the host architecture" {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 92ea3e3

Please sign in to comment.