Skip to content

Conversation

pugong2019
Copy link

  1. Use LLM to generate the test case code for posix module
  2. Totally generate 108 cases
  3. Posix moudle's coverage improve from 23% to 50.7%

@lum1n0us lum1n0us added the ai-assistant It is created by an AI assistant or with the help of an AI assistant. label Sep 14, 2025
@pugong2019 pugong2019 force-pushed the AI_WAMR_2.4.1_Coverage branch from 462192c to c8cee3c Compare September 14, 2025 06:01
os_end_blocking_op();
blocking_op_started = false;

// Test that ending again is safe (should be idempotent)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why should it be idempotent?

my impression is that this file is testing what the current implementation happens to be.
we should test the documented/defined functionality instead, IMO.

Copy link
Collaborator

@lum1n0us lum1n0us Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should test the documented/defined functionality instead, IMO.

It will be in the next phase. Currently, this task is focusing on covering the code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my point is that having these tests, especially with these comments, can give readers a wrong impression that it's a part of the API contract.

@yamt
Copy link
Collaborator

yamt commented Sep 16, 2025

Use LLM to generate the test case code for posix module

do we have any policy about ai-generated code?

@lum1n0us
Copy link
Collaborator

Use LLM to generate the test case code for posix module

do we have any policy about ai-generated code?

❓ What kind of policy are we seeking?

@yamt
Copy link
Collaborator

yamt commented Sep 16, 2025

Use LLM to generate the test case code for posix module

do we have any policy about ai-generated code?

❓ What kind of policy are we seeking?

the safest one is "do not accept any ai-generated code".
copyright and ai-generated materials is still a controversial topic.

@pugong2019 pugong2019 force-pushed the AI_WAMR_2.4.1_Coverage branch from c8cee3c to 8a44eb2 Compare September 16, 2025 05:52
@lum1n0us
Copy link
Collaborator

🤔 I am not sure about "any ai-generated code". AI assistants, like VSCode Copilot, GPT, and others, are helping us in various ways in our daily work. It's hard to determine which part of a PR is AI-generated, which part is typed by a human without referring to any AI generation, and which part is copied/pasted by a human from AI-generated content.

This makes review very important and might require some additional rules for such PRs regarding copyright considerations? (personally, Definitely no idea)

@lum1n0us
Copy link
Collaborator

@pugong2019 pugong2019 force-pushed the AI_WAMR_2.4.1_Coverage branch from 8a44eb2 to 99c8714 Compare September 16, 2025 09:14
@pugong2019 pugong2019 force-pushed the AI_WAMR_2.4.1_Coverage branch from 99c8714 to e387c2a Compare September 16, 2025 10:30
Copy link
Collaborator

@lum1n0us lum1n0us left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not finished. Still WIP...

${POSIX_PLATFORM_DIR}/posix_file.c
${POSIX_PLATFORM_DIR}/posix_socket.c
${POSIX_PLATFORM_DIR}/posix_blocking_op.c
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POSIX_SOURCEF_FILES isn't necessary. should be removed.

set(unit_test_sources
${POSIX_TEST_SOURCE}
${POSIX_SOURCE_FILES}
${WAMR_RUNTIME_LIB_SOURCE}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WAMR_RUNTIME_LIB_SOURCE includes POSIX_SOURCE_FILES. L44 should be removed.

# Create test executable
add_executable(posix_platform_test ${unit_test_sources})
enable_testing()
include(GoogleTest)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L50 and L51 are not necessary. unit_common.cmake includes that part.

cmake_minimum_required(VERSION 3.14)

project(test-posix-platform)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to consider how to manage situations where the host(or targeting) system isn't POSIX-like. My poor suggestion is something like:

if(UNIX AND NOT APPLE)
    message(STATUS "This is a POSIX-like system (Linux or similar).")
elseif(APPLE)
    message(STATUS "This is macOS, which is POSIX-compliant.")
else()
    message(STATUS "This is not a POSIX-like system.")
endif()

add_definitions(-DRUN_ON_LINUX)

set(WAMR_BUILD_LIBC_BUILTIN 1)
set(WAMR_BUILD_LIBC_WASI 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to open both. Or even any one.

};

// Step 3: Blocking Operations Tests for Coverage Improvement

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are ~6 functions in core/shared/platform/common/posix/posix_blocking_op.c, and the cases focus only on 2 of them. Since we aim to expand coverage quickly, it's preferable to create a few cases for each function rather than numerous cases for just one function.

@yamt
Copy link
Collaborator

yamt commented Sep 17, 2025

🤔 I am not sure about "any ai-generated code". AI assistants, like VSCode Copilot, GPT, and others, are helping us in various ways in our daily work. It's hard to determine which part of a PR is AI-generated, which part is typed by a human without referring to any AI generation, and which part is copied/pasted by a human from AI-generated content.

This makes review very important and might require some additional rules for such PRs regarding copyright considerations? (personally, Definitely no idea)

i think there are two separate things:

  • if we trust the patch submitters about the origin of the code. (we usually just trust them.)
  • the policy about ai-generated patches

your point about review importance is for the former, right?
my concern is about the latter.

@yamt
Copy link
Collaborator

yamt commented Sep 17, 2025

Is this the concern mentioned above? https://www.bloomberglaw.com/external/document/X4H9CFB4000000/copyrights-professional-perspective-ip-issues-with-ai-code-gener

yes. (i only glanced at the article)

@yamt
Copy link
Collaborator

yamt commented Sep 17, 2025

Use LLM to generate the test case code for posix module

which LLM and what contract?

i've heard some LLM providers offer users some protections. eg. https://blogs.microsoft.com/on-the-issues/2023/09/07/copilot-copyright-commitment-ai-legal-concerns/

Posix moudle's coverage improve from 23% to 50.7%

where/how can i see the number?

else {
EXPECT_EQ(__WASI_ENOTSUP, result);
}
} No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMM,

  • static __wasi_errno_t wasi_clockid_to_clockid(__wasi_clockid_t in, clockid_t *out) and static __wasi_timestamp_t timespec_to_nanoseconds(const struct timespec *ts) should be called directly rather than through other functions.
  • It seems the cases attempt to cover edge scenarios but mostly fall short. A quick way to cover corners is to prepare values based on the argument types, such as using 0, negative values, positive values, INT32_MIN, and INT32_MAX for int32_t types. However, this approach resembles using a test plan.
  • If increasing coverage is not the plan, perhaps fewer cases will suffice.


// Test PROCESS_CPUTIME_ID clock if supported
__wasi_errno_t result =
os_clock_res_get(__WASI_CLOCK_PROCESS_CPUTIME_ID, &resolution);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result will be influenced by the compilation flag CLOCK_PROCESS_CPUTIME_ID. How should we address that? It is better not enable both assertions at L38 and L41 at the same time.

}

// Test THREAD_CPUTIME_ID clock if supported
result = os_clock_res_get(__WASI_CLOCK_THREAD_CPUTIME_ID, &resolution);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.


// Test PROCESS_CPUTIME_ID clock
__wasi_errno_t result =
os_clock_time_get(__WASI_CLOCK_PROCESS_CPUTIME_ID, 0, &time);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above


// Test THREAD_CPUTIME_ID clock
__wasi_errno_t result =
os_clock_time_get(__WASI_CLOCK_THREAD_CPUTIME_ID, 0, &time);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

rmdir(test_dir);
}
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better have some comments to explain the purpose of each test and any assumptions made

EXPECT_GT(strlen(buffer), 0);

// Should contain RSS information
EXPECT_NE(nullptr, strstr(buffer, "RSS"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the result depends on WASM_ENABLE_MEMORY_PROFILING. Need a way to handle it.

@lum1n0us lum1n0us changed the title [AI] Add test case code for posix module coverage improve: from 23% to 50% [UNIT] Add test case code for posix module coverage improve: from 23% to 50% Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai-assistant It is created by an AI assistant or with the help of an AI assistant.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants