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

Add unit tests for Test Coverage #685

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b4ac43a
Add gcov example in testfiles folder; Testing on CI
radurentea Mar 28, 2022
6ebcdbb
Add unit test for getGcovFilterPaths function
radurentea Mar 29, 2022
bb06457
Fix getGcovFilterPaths unit test
radurentea Mar 29, 2022
5f1ab9a
Fix getGcovFilterPaths unit test v2
radurentea Mar 29, 2022
5be7c0b
Update testCoverage.test.ts
radurentea Mar 29, 2022
d881f87
Testing buildJson response on CI
radurentea Mar 30, 2022
36a99d2
Add .gcda and .gcno mockup files for buildJson unit test
radurentea Mar 30, 2022
4dc82ef
Fix testFiles path; Add mockfiles inside gcov folder
radurentea Mar 31, 2022
ee59868
testing result on ci
radurentea Mar 31, 2022
166ae6d
Update compilerPath to default
radurentea Mar 31, 2022
f0b6b56
Update workspace path
radurentea Apr 4, 2022
ec55d63
Move C files into components/sample
radurentea Mar 31, 2022
4231a77
Moving files outside sample folder
radurentea Apr 4, 2022
8fcd3ce
Update idf variables
radurentea Apr 4, 2022
9dc4229
Add dependencies
radurentea Apr 6, 2022
d2da994
Revert "Add dependencies"
radurentea Apr 6, 2022
bcdf476
Removing workspaceFolder
radurentea Apr 6, 2022
fb3a3e9
Revert "Removing workspaceFolder"
radurentea Apr 6, 2022
21352e4
Update testCoverage.test.ts
radurentea Apr 6, 2022
9af4652
Update c_cpp_properties.json
radurentea Apr 6, 2022
2e867f6
Revert "Update c_cpp_properties.json"
radurentea Apr 6, 2022
93158a3
Removing .dovcontainer
radurentea Apr 6, 2022
7ae6380
Revert "Removing .dovcontainer"
radurentea Apr 7, 2022
94dda21
Replace config variables with env variables
radurentea May 3, 2022
190b511
Revert "Replace config variables with env variables"
radurentea May 3, 2022
7a8e562
Testing if the test results are changing on CI
radurentea May 3, 2022
e0ff6bf
Revert "Testing if the test results are changing on CI"
radurentea May 3, 2022
d3648d9
Testing on CI - removing paths from settings.json
radurentea May 3, 2022
614d62e
Replacing example folders
radurentea May 3, 2022
a03023a
Testing on CI - removing mockup_files folder
radurentea May 3, 2022
68d13d8
Fix unit test for buildJson function
radurentea May 4, 2022
ad60a4f
Add unit test for buildHtml function
radurentea May 4, 2022
a62a3fb
Fix test unit for buildHtml function; Add comments for some test cove…
radurentea May 5, 2022
6323c4c
Add test unit for generateCoverageForEditors()
radurentea May 9, 2022
51b36a3
Remove unnecessary files; Add description;
radurentea Jun 6, 2022
f9a5343
Add gcda and gcno mockup files
radurentea Jun 9, 2022
fa60585
Revert "Add gcda and gcno mockup files"
radurentea Jun 9, 2022
45ae0e4
Re-run checks
radurentea Nov 7, 2022
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
2 changes: 1 addition & 1 deletion src/coverage/coverageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export async function buildJson(dirPath: vscode.Uri) {
],
dirPath.fsPath.replace(/\\/g, "/")
);
return JSON.parse(result);
return JSON.stringify(result);
}

export async function buildHtml(dirPath: vscode.Uri) {
Expand Down
56 changes: 49 additions & 7 deletions src/test/suite/testCoverage.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,61 @@
import * as assert from "assert";
import * as vscode from "vscode";
import { json } from "stream/consumers";
import { getGcovExecutable, buildJson } from "../../coverage/coverageService";
import { CoverageRenderer } from "../../coverage/renderer";
import { join } from "path";
import {
getGcovExecutable,
buildJson,
getGcovFilterPaths,
buildHtml,
generateCoverageForEditors,
} from "../../coverage/coverageService";

suite("Test Coverage Unit Tests", () => {
const workspace = vscode.Uri.file(join(__dirname, "../../../testFiles/gcov"));
test("gcov executables based on idfTarget", () => {
const esp32c3 = getGcovExecutable("esp32c3")
const esp32s2 = getGcovExecutable("esp32s2")
const esp32s3 = getGcovExecutable("esp32s3")
const esp32 = getGcovExecutable("esp32")
const esp32c3 = getGcovExecutable("esp32c3");
const esp32s2 = getGcovExecutable("esp32s2");
const esp32s3 = getGcovExecutable("esp32s3");
const esp32 = getGcovExecutable("esp32");

assert.equal(esp32c3, "riscv32-esp-elf-gcov");
assert.equal(esp32s2, "xtensa-esp32s2-elf-gcov");
assert.equal(esp32s3, "xtensa-esp32s3-elf-gcov");
assert.equal(esp32, "xtensa-esp32-elf-gcov");
});

test("getGcovFilterPaths", async () => {
const pathsToFilter = await getGcovFilterPaths(workspace);
const example = ["--filter", `${process.env.IDF_PATH}/components`];
assert.equal(JSON.stringify(example), JSON.stringify(pathsToFilter))
})

// Tests if buildJson returns a double stringified object that has the following properties: "files", "gcovr/format_version"
test("buildJson", async () => {
const result = await buildJson(workspace);
const parsedResult = JSON.parse(JSON.parse(result));
assert.ok(parsedResult.files);
assert.ok(parsedResult["gcovr/format_version"]);
})

// Tests if buildHtml returns a string cointanting html content.
test("buildHtml", async () => {
const result = await buildHtml(workspace);
assert.equal(result.slice(result.length - 8), "</html>\n");
assert.equal(result.slice(0,15), "<!DOCTYPE html>");
})

// Tests the parameters and the result not to be undefinied
test("generateCoverageForEditors", async () => {
const editors = vscode.window.visibleTextEditors;
const gcovObj = await buildJson(workspace);
const result = await generateCoverageForEditors(
workspace,
editors,
gcovObj
);

assert.ok(editors);
assert.ok(gcovObj);
assert.ok(result);
})
});
8 changes: 8 additions & 0 deletions testFiles/gcov/gcov_example_func.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>


void blink_dummy_func(void)
{
static int i;
printf("blink_dummy_func: Counter = %d\n", i++);
}
60 changes: 60 additions & 0 deletions testFiles/gcov/gcov_example_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* Blink Example with covergae info

This example code is in the Public Domain (or CC0 licensed, at your option.)

Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_app_trace.h"
#include "sdkconfig.h"

/* Can use project configuration menu (idf.py menuconfig) to choose the GPIO
to blink, or you can edit the following line and set a number here.
*/
#define BLINK_GPIO CONFIG_BLINK_GPIO

void blink_dummy_func(void);
void some_dummy_func(void);

static void blink_task(void *pvParameter)
{
// The first two iterations GCOV data are dumped using call to esp_gcov_dump() and OOCD's "esp32 gcov dump" command.
// After that they can be dumped using OOCD's "esp32 gcov" command only.
int dump_gcov_after = -2;
/* Configure the IOMUX register for pad BLINK_GPIO (some pads are
muxed to GPIO on reset already, but some default to other
functions and need to be switched to GPIO. Consult the
Technical Reference for a list of pads and their default
functions.)
*/
gpio_reset_pin(BLINK_GPIO);
/* Set the GPIO as a push/pull output */
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);

while(1) {
/* Blink off (output low) */
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(500 / portTICK_PERIOD_MS);
/* Blink on (output high) */
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(500 / portTICK_PERIOD_MS);
blink_dummy_func();
some_dummy_func();
if (dump_gcov_after++ < 0) {
// Dump gcov data
printf("Ready to dump GCOV data...\n");
esp_gcov_dump();
printf("GCOV data have been dumped.\n");
}
}
}

void app_main(void)
{
xTaskCreate(&blink_task, "blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
}
3 changes: 2 additions & 1 deletion testFiles/testWorkspace/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"window.dialogStyle": "custom",
"idf.customExtraPaths": "${env:PATH}",
"idf.customExtraVars": "{\"OPENOCD_SCRIPTS\": \"${env:OPENOCD_SCRIPTS}\" }",
"idf.notificationSilentMode": true
"idf.notificationSilentMode": true,
"idf.adapterTargetName": "esp32"
}