-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/add_bsd_fls' into 'master'
feat(linux): added fls() on Linux See merge request espressif/esp-idf!28807
- Loading branch information
Showing
11 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* SPDX-FileCopyrightText: Copyright (c) 1990, 1993 The Regents of the University of California. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: BSD-4-Clause-UC | ||
* | ||
* SPDX-FileContributor: 2024 Espressif Systems (Shanghai) CO LTD | ||
*/ | ||
|
||
#include "strings.h" | ||
|
||
int fls(unsigned int mask) | ||
{ | ||
if (mask == 0) { | ||
return (0); | ||
} | ||
|
||
return (sizeof(mask) << 3) - __builtin_clz(mask); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* | ||
* This is a helper include for fls(), which is present in the ESP-IDF toolchains and MacOS, but not on Linux. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
int fls(unsigned int value); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#include_next <strings.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps | ||
|
||
components/linux/test_apps/linux_test: | ||
enable: | ||
- if: IDF_TARGET in ["linux"] | ||
reason: Test app is specifically for the linux target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# For more information about build system see | ||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html | ||
# The following five lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
set(COMPONENTS main) | ||
project(linux_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
| Supported Targets | Linux | | ||
| ----------------- | ----- | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
idf_component_register(SRCS "linux_test.c" | ||
INCLUDE_DIRS "." | ||
PRIV_REQUIRES unity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "unity.h" | ||
#include "unity_test_runner.h" | ||
#include "unity_test_utils_memory.h" | ||
#include "esp_log.h" | ||
#include <strings.h> | ||
|
||
static const char* TAG = "event_test_app"; | ||
|
||
void setUp(void) | ||
{ | ||
// If heap tracing is enabled in kconfig, leak trace the test | ||
unity_utils_set_leak_level(0); | ||
unity_utils_record_free_mem(); | ||
} | ||
|
||
void tearDown(void) | ||
{ | ||
unity_utils_evaluate_leaks(); | ||
} | ||
|
||
TEST_CASE("fls(0) = 0", "[fls]") | ||
{ | ||
TEST_ASSERT_EQUAL(0, fls(0)); | ||
} | ||
|
||
TEST_CASE("fls(1) = 1", "[fls]") | ||
{ | ||
TEST_ASSERT_EQUAL(1, fls(1)); | ||
} | ||
|
||
TEST_CASE("fls(0xF000) = 16", "[fls]") | ||
{ | ||
TEST_ASSERT_EQUAL(16, fls(0xF000)); | ||
} | ||
|
||
TEST_CASE("fls(0x80000000) = 32", "[fls]") | ||
{ | ||
TEST_ASSERT_EQUAL(32, fls(0x80000000)); | ||
} | ||
|
||
void app_main(void) | ||
{ | ||
ESP_LOGI(TAG, "Running linux test app"); | ||
unity_run_menu(); | ||
} |
12 changes: 12 additions & 0 deletions
12
components/linux/test_apps/linux_test/pytest_linux_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
# SPDX-License-Identifier: CC0-1.0 | ||
import pytest | ||
from pytest_embedded_idf.dut import IdfDut | ||
|
||
|
||
@pytest.mark.linux | ||
@pytest.mark.host_test | ||
def test_linux_component(dut: IdfDut) -> None: | ||
dut.expect_exact('Press ENTER to see the list of tests.') | ||
dut.write('![ignore]') | ||
dut.expect(r'\d{1} Tests 0 Failures 0 Ignored', timeout=10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_IDF_TARGET="linux" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters