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

Fixes of Broken CI #27

Merged
merged 23 commits into from
Mar 22, 2023
Merged

Fixes of Broken CI #27

merged 23 commits into from
Mar 22, 2023

Conversation

MohitMaliFtechiz
Copy link
Collaborator

@MohitMaliFtechiz MohitMaliFtechiz commented Mar 3, 2023

Since, We have changed the folder structure, generated files destination to build folder. That's why CI is failing on testing.

  • Fixed the paths according to new folder structure.
  • We have removed the Reader, Searcher in latest libkiwix, so in this PR we have refactored the test cases as well according to the latest libkiwix.

lib/build.gradle Outdated Show resolved Hide resolved
@mgautierfr mgautierfr mentioned this pull request Mar 8, 2023
@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as draft March 9, 2023 09:45
@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Mar 14, 2023

@mgautierfr ,

Most of the test cases i have refactored and they are running successfully.
but in two test case i'm facing error.

 String s = getTextFileContent("small_zimfile_data/main.html");
        String c = archive.getEntryByPath("A/main.html").getItem(true).getData().getData();
        assertEquals(s, c);
  • when i'm comparing main page data of zim file. 2 methods i'm using
    i) getTextFileContent() in this method we are getting fileContent as string.
    ii) from Blob object which i have get from Archive class.

in both methods we have difference of spaces that's why test cases are failing on this.

Screenshot from 2023-03-10 16-17-59

  • when i'm getting Book from Library through library.getBookById(bookid) then it's giving compile time error
/media/hp-pc03/D/java-libkiwix/lib/src/test/../main/cpp/utils.h:71: void setPtr(JNIEnv*, jobject, std::shared_ptr<_Tp>&&, const char*) [with T = const kiwix::Book; JNIEnv = JNIEnv_; jobject = _jobject*]: Assertion `env->GetLongField(thisObj, fieldId) == 0' failed.

Edited

I'm adding new test cases for Searcher to test the search functionality when i'm creating the Query object to pass in searcher it's giving UnsatisfiedLinkError error. But i have include all .so and java files in test cases, am i missing something here? Can you please help me out from this.

java.lang.UnsatisfiedLinkError: 'long org.kiwix.libzim.Query.setNativeQuery(java.lang.String)'
	at org.kiwix.libzim.Query.setNativeQuery(Native Method)
	at org.kiwix.libzim.Query.<init>(Query.java:25)
	at test.testSearcher(test.java:196)

@mgautierfr
Copy link
Member

in both methods we have difference of spaces that's why test cases are failing on this.

You have modified the spaces in small_zimfile_data/main.html (https://github.com/kiwix/java-libkiwix/pull/27/files#diff-8f490b9cc9fd6bb56c1ac0d26c4da20d9bab94d312b34f3953fce3ff1cafc5a5R1-R11)
So your test probably compare the modified main.html with what is the zim file (probably create with the unmodified file)

@MohitMaliFtechiz
Copy link
Collaborator Author

You have modified the spaces in small_zimfile_data/main.html (https://github.com/kiwix/java-libkiwix/pull/27/files#diff-8f490b9cc9fd6bb56c1ac0d26c4da20d9bab94d312b34f3953fce3ff1cafc5a5R1-R11)
So your test probably compare the modified main.html with what is the zim file (probably create with the unmodified file)

For now i have modify the the main.html to pass the test cases (to write new test cases and match 100% code coverage report), without modifying the main.html the spaces error is ouurcing.

@mgautierfr
Copy link
Member

I've just tested small.zim and there is no extra space in the content. So I suspect the zim file has been created with a content without space.

I suggest you modify main.html has you have already done. But be sure to put this change in a specific commit with a commit message explicating why we do this change. Especially that we have tested the zim file itself and that the wrapper is not in cause here.

@MohitMaliFtechiz
Copy link
Collaborator Author

Thanks, I have done the changes in main.html as you suggested.

when i'm getting Book from Library through library.getBookById(bookid) then it's giving compile time error
Edited
I'm adding new test cases for Searcher to test the search functionality when i'm creating the Query object to pass in searcher it's giving UnsatisfiedLinkError error. But i have include all .so and java files in test cases, am i missing something here? Can you please help me out from this.

can you please help me out from these error so i can move forward to right more new test cases for library and searcher.

@kelson42
Copy link
Contributor

@mgautierfr ?

@mgautierfr
Copy link
Member

I cannot compile the test on my computer :

./gradlew createCodeCoverageReport

> Task :lib:createCodeCoverageReport
-- JNI_INCLUDE_DIRS=/usr/lib/jvm/java/include;/usr/lib/jvm/java/include/linux;/usr/lib/jvm/java/include
-- JNI_LIBRARIES=/usr/lib/jvm/java/lib/libjawt.so;/usr/lib/jvm/java/lib/server/libjvm.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mgautier/Project/KIWIX/JAVA/java-libkiwix2/lib/src/test
[  4%] Building CXX object CMakeFiles/buildkiwix.dir/home/mgautier/Project/KIWIX/JAVA/java-libkiwix2/lib/src/main/cpp/libkiwix/book.cpp.o
/home/mgautier/Project/KIWIX/JAVA/java-libkiwix2/lib/src/main/cpp/libkiwix/book.cpp:21:10: erreur fatale: jni.h : Aucun fichier ou dossier de ce type
   21 | #include <jni.h>
      |          ^~~~~~~
compilation terminée.
make[2]: *** [CMakeFiles/buildkiwix.dir/build.make:76 : CMakeFiles/buildkiwix.dir/home/mgautier/Project/KIWIX/JAVA/java-libkiwix2/lib/src/main/cpp/libkiwix/book.cpp.o] Erreur 1
make[1]: *** [CMakeFiles/Makefile2:83 : CMakeFiles/buildkiwix.dir/all] Erreur 2
make: *** [Makefile:91 : all] Erreur 2
Starting a Gradle Daemon, 1 busy and 2 stopped Daemons could not be reused, use --status for details
> Task :lib:copyBuildKiwixSoFile NO-SOURCE

BUILD SUCCESSFUL in 4s
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
JUnit version 4.13
Exception in thread "main" java.lang.UnsatisfiedLinkError: no buildkiwix in java.library.path: [/home/mgautier/Project/KIWIX/JAVA/java-libkiwix2/lib/build]
        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2673)
        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:830)
        at java.base/java.lang.System.loadLibrary(System.java:1873)
        at test.<clinit>(test.java:15)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:398)
        at org.junit.internal.Classes.getClass(Classes.java:42)
        at org.junit.internal.Classes.getClass(Classes.java:27)
        at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:98)
        at org.junit.runner.JUnitCommandLineParseResult.parseArgs(JUnitCommandLineParseResult.java:50)
        at org.junit.runner.JUnitCommandLineParseResult.parse(JUnitCommandLineParseResult.java:44)
        at org.junit.runner.JUnitCore.runMain(JUnitCore.java:72)
        at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
!!! ERROR: Unit test failed

> Task :lib:createCodeCoverageReport FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':lib:createCodeCoverageReport'.
> Process 'command 'sh'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
1 actionable task: 1 executed

@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Mar 16, 2023

@mgautierfr ,

Task :lib:createCodeCoverageReport
-- JNI_INCLUDE_DIRS=/usr/lib/jvm/java/include;/usr/lib/jvm/java/include/linux;/usr/lib/jvm/java/include
-- JNI_LIBRARIES=/usr/lib/jvm/java/lib/libjawt.so;/usr/lib/jvm/java/lib/server/libjvm.so

these are the JNI_INCLUDE_DIRS of your computer, After changing these in test CMakeLists.txt it'll compile on you computer.

/usr/lib/jvm/java/include
/usr/lib/jvm/java/include/linux

Edited
I have removed the absolute path of JNI_INCLUDE_DIRS , now it'll automatically picks the JNI_INCLUDE_DIRS .

Bookmark wrapper can be created using two ways:
- From a existing (cpp) bookmark (done internally by Library wrapper code)
- As a totally new one (empty) the java code will have to setup (using
  `set*` methods).

If the `Bookmark` constructor always create an empty new cpp bookmark,
when we set the wrapper to point to the existing bookmark, we will have a
leak of the new created bookmark.

As we want to keep the "basic" constructor as the normal java api to
create an empty bookmark, we need another (private) constructor to avoid
the construction of an empty bookmark.

The new constructor take a handle and directly set the `nativeHandle`.

On `Library.getBookmarks` we cannot use the helper `BUILD_WRAPPER` and
we must use "internal" function to use the `(J)V` constructor instead of
the basic `()V`.
@mgautierfr
Copy link
Member

@MohitMaliFtechiz I have fixed the cpp wrapping (as far as testing points to broken cpp).

However, I have tests failing about wrong indentation in expected html. I let you fix that.

… this commit i have removed that extra spaces to pass test cases
@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (main@4b5cc44). Click here to learn what that means.
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #27   +/-   ##
=======================================
  Coverage        ?   38.20%           
  Complexity      ?       15           
=======================================
  Files           ?       24           
  Lines           ?       89           
  Branches        ?        6           
=======================================
  Hits            ?       34           
  Misses          ?       51           
  Partials        ?        4           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@kelson42
Copy link
Contributor

I'm in favour of merging this ASAP. extending testing and code coverage can be done in furthet PRs.

@MohitMaliFtechiz
Copy link
Collaborator Author

I'm in favour of merging this ASAP. extending testing and code coverage can be done in furthet PRs.

@kelson42 Ok, I have create a ticket for adding more new test cases for latest wrapper #29 . @mgautierfr can you please review this PR.

@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as ready for review March 22, 2023 05:47
@MohitMaliFtechiz
Copy link
Collaborator Author

  • when i'm getting Book from Library through library.getBookById(bookid) then it's giving compile time error
/media/hp-pc03/D/java-libkiwix/lib/src/test/../main/cpp/utils.h:71: void setPtr(JNIEnv*, jobject, std::shared_ptr<_Tp>&&, const char*) [with T = const kiwix::Book; JNIEnv = JNIEnv_; jobject = _jobject*]: Assertion `env->GetLongField(thisObj, fieldId) == 0' failed.

Edited

I'm adding new test cases for Searcher to test the search functionality when i'm creating the Query object to pass in searcher it's giving UnsatisfiedLinkError error. But i have include all .so and java files in test cases, am i missing something here? Can you please help me out from this.

java.lang.UnsatisfiedLinkError: 'long org.kiwix.libzim.Query.setNativeQuery(java.lang.String)'
	at org.kiwix.libzim.Query.setNativeQuery(Native Method)
	at org.kiwix.libzim.Query.<init>(Query.java:25)
	at test.testSearcher(test.java:196)

@mgautierfr , have you find something on these error?
Other Library functions are working fine but 2 methods are giving error first one is getBookById() which i have mentioned earlier and another one is getArchiveById() .

@kelson42
Copy link
Contributor

kelson42 commented Mar 22, 2023

  • when i'm getting Book from Library through library.getBookById(bookid) then it's giving compile time error
/media/hp-pc03/D/java-libkiwix/lib/src/test/../main/cpp/utils.h:71: void setPtr(JNIEnv*, jobject, std::shared_ptr<_Tp>&&, const char*) [with T = const kiwix::Book; JNIEnv = JNIEnv_; jobject = _jobject*]: Assertion `env->GetLongField(thisObj, fieldId) == 0' failed.

Edited
I'm adding new test cases for Searcher to test the search functionality when i'm creating the Query object to pass in searcher it's giving UnsatisfiedLinkError error. But i have include all .so and java files in test cases, am i missing something here? Can you please help me out from this.

java.lang.UnsatisfiedLinkError: 'long org.kiwix.libzim.Query.setNativeQuery(java.lang.String)'
	at org.kiwix.libzim.Query.setNativeQuery(Native Method)
	at org.kiwix.libzim.Query.<init>(Query.java:25)
	at test.testSearcher(test.java:196)

@mgautierfr , have you find something on these error? Other Library functions are working fine but 2 methods are giving error first one is getBookById() which i have mentioned earlier and another one is getArchiveById() .

@MohitMaliDeveloper Why do we have a green CI if there an error? Please move everything which is not mandatory and still NOK to #30. This PR has to be ready to review = perfect.

@MohitMaliFtechiz
Copy link
Collaborator Author

@MohitMaliDeveloper Why do we have a green CI if there an error?

@kelson42 , we haven't included the failing test cases in this PR for writing new test cases we commented that part of code.

Please move everything which is not mandatory and still NOK to #30.

Okay, I'm removing the commented code from here and moving these test cases to #30 .

Copy link
Member

@mgautierfr mgautierfr left a comment

Choose a reason for hiding this comment

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

Few things to change on the code itself.

More generally, we have to test the wrapper. Meanning we have to run all functions and check they are not broken. Testing the behavior (returned values) of such functions is nice but it is not what we want to test. The behavior of libkiwix is tested in libkiwix side.

The same way, you have fixed existing tests to make it pass with the new api. But it would be better to fully adapt the tests to the new api and not being stuck with the old logic.

(And see my answers to the discussion in the PR comments)

Comment on lines +5 to +27
SHARED
${PROJECT_SOURCE_DIR}/../main/cpp/libkiwix/book.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libkiwix/bookmark.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libkiwix/filter.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libkiwix/illustration.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libkiwix/kiwixicu.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libkiwix/kiwixserver.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libkiwix/library.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libkiwix/manager.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/archive.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/blob.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/entry.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/entry_iterator.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/item.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/query.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/search.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/search_iterator.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/searcher.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/suggestion_item.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/suggestion_iterator.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/suggestion_search.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/libzim/suggestion_searcher.cpp
${PROJECT_SOURCE_DIR}/../main/cpp/utils.h
Copy link
Member

Choose a reason for hiding this comment

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

Tests should not recompile the wrapper.
It should use the already compiled wrapper (with build target) as kiwix-android will use it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are not running test cases on android architecture its linux variant upon which test needs to run .

lib/src/test/test.java Outdated Show resolved Hide resolved
lib/src/test/test.java Outdated Show resolved Hide resolved
@mgautierfr
Copy link
Member

@mgautierfr , have you find something on these error?

I have fixed all cpp errors I can found by running the test on my computer (and the CI). As @kelson42 said, the tests must NOT pass if there is error. This is the purpose of tests.

However, I agree with @kelson42, if this pr is good enough to have tests running (and it is), we can merge it right now and fix things later.

@MohitMaliFtechiz
Copy link
Collaborator Author

Few things to change on the code itself.

More generally, we have to test the wrapper. Meanning we have to run all functions and check they are not broken. Testing the behavior (returned values) of such functions is nice but it is not what we want to test. The behavior of libkiwix is tested in libkiwix side.

The same way, you have fixed existing tests to make it pass with the new api. But it would be better to fully adapt the tests to the new api and not being stuck with the old logic.

(And see my answers to the discussion in the PR comments)

Let me conclude what i understood by your comment , We have to test the wrapper changes functionality on android side so after building the wrapper , we have compile kiwix-android replace the .aar file and run the test as we are running it for android by this way we can ensure wrapper is working fine. let me know if this is making sense.

@mgautierfr
Copy link
Member

Let me conclude what i understood by your comment , We have to test the wrapper changes functionality on android side so after building the wrapper , we have compile kiwix-android replace the .aar file and run the test as we are running it for android by this way we can ensure wrapper is working fine. let me know if this is making sense.

Not exactly.
kiwix-android will use a precompiled java-libkiwix .aar file. It will not compile it nor include the wrapper source in it own build scripts. It will just "import" libkiwix and use it.
The testing of java-libkiwix must do the same. We build the java-libkiwix aar with the gradle build target and the testing use that aar. We may make the test (or generateCodecoverage) target depends of build target is testing depends of build. But the testing build script itself must not compile the wrapper or include the cpp sources.

@kelson42 kelson42 merged commit 66ebc4e into main Mar 22, 2023
@kelson42 kelson42 deleted the FixBrokenCi branch March 22, 2023 16:32
@mgautierfr
Copy link
Member

We have merged this PR as it is technically working. But few things still have to be improved. I have open the issue #31 for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants