GitLab will be upgraded on June 2nd 2020 at 2.00 pm (AEDT) to 3.00 pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to local Gitlab admin team.

Commit 23932cb1 authored by Kunshan Wang's avatar Kunshan Wang

WIP: Tested id_of and name_of.

parent 325749b4
......@@ -101,15 +101,21 @@ object ClientAccessibleClassExposer {
val ptr = NativeClientSupport.stringPool.getOrElseUpdate(str, {
val bytes = str.getBytes(StandardCharsets.US_ASCII)
val newPtr = jnrMemoryManager.allocateDirect(bytes.size + 1)
newPtr.put(0L, bytes, 0, 0)
newPtr.put(0L, bytes, 0, bytes.length)
newPtr.putByte(bytes.length, 0)
private def getObj[T](buffer: Buffer, index: Int, orm: ObjectReferenceManager[T]): T = {
val addr = buffer.getLong(index)
val arg0 = buffer.getLong(index)
val objAddr = theMemory.getAddress(arg0)
val obj = orm.get(jnrMemoryManager.newPointer(objAddr))
if (obj == null) {
throw new UvmRefImplException("Exposed object not found. Address: %d 0x%x".format(objAddr, objAddr))
// Reflection utils.
......@@ -13,31 +13,37 @@ class NativeClientSupportTest extends UvmBundleTesterBase {
"uvm.refimpl.nat" -> DEBUG)
val fileName = "./tests/c-snippets/"
if (!new {
throw new RuntimeException("Need to compile the library. cd into tests/c-snippets and invoke 'make'.")
trait NcsTestsLib {
def test_basic(mvm: Word): Unit
def test_basic(mvm: Word, theID: Int, theName: String): Int
val ncs_tests = LibraryLoader.create(classOf[NcsTestsLib]).load(fileName)
"The ClientAccessibleClassExposer" should "enumerate declared methods" in {
val cace = new ClientAccessibleClassExposer(NativeMuVM)
val microVMAddr = NativeClientSupport.exposeMicroVM(microVM)
val funcTable = cace.makeFuncTable(microVMAddr)
val funcTablePtr = NativeClientSupport.funcTableToPointer(funcTable)
val header = funcTablePtr.getAddress(0)
val mvm =NativeClientSupport.microVMs.get(jnrMemoryManager.newPointer(header))
val mvm = NativeClientSupport.microVMs.get(jnrMemoryManager.newPointer(header))
mvm shouldBe microVM
val theName = "@i64"
val theID = microVM.idOf(theName)
val result = ncs_tests.test_basic(funcTable, theID, theName)
if (result == 0) {
fail("Failed in the native program.")
\ No newline at end of file
#include <stdio.h>
#include <string.h>
#include <muapi.h>
void test_basic(MuVM *mvm) {
int test_basic(MuVM *mvm, int theID, char *theName) {
printf("[C] header: %p\n", mvm->header);
printf("[C] new_context: %p\n", mvm->new_context);
printf("[C] id_of: %p\n", mvm->id_of);
printf("[C] name_of: %p\n", mvm->name_of);
printf("[C] set_trap_handler: %p\n", mvm->set_trap_handler);
int id = mvm->id_of(mvm, theName);
printf("[C] id = %d\n", id);
if (id != theID) {
printf("[C] ID %d is not equal to %d\n", id, theID);
return 0;
char *name = mvm->name_of(mvm, theID);
printf("[C] name = %s\n", name);
if (strcmp(name, theName) != 0) {
printf("[C] name %s is not equal to %s\n", name, theName);
return 0;
return 1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment