Commit 325749b4 authored by Kunshan Wang's avatar Kunshan Wang

WIP: basic tests

parent 43d60570
This diff is collapsed.
......@@ -249,4 +249,12 @@ object NativeClientSupport {
* alive so that the native program can access them.
val stringPool = HashMap[String, Pointer]()
// Expose and unexpose objects
def exposeMicroVM(microVM: MicroVM): Word = microVMs.add(microVM).address()
def exposeMuCtx(muCtx: MuCtx): Word = muCtxs.add(muCtx).address()
def exposeMuValue(muValue: MuValue): Word = muValues.add(muValue).address()
def unexposeMicroVM(addr: Long): Unit = microVMs.remove(jnrMemoryManager.newPointer(addr))
def unexposeMuCtx(addr: Long): Unit = muCtxs.remove(jnrMemoryManager.newPointer(addr))
def unexposeMuValue(addr: Long): Unit = muValues.remove(jnrMemoryManager.newPointer(addr))
\ No newline at end of file
package uvm.refimpl.nat
import scala.reflect.runtime.universe
import ch.qos.logback.classic.Level._
import uvm.refimpl.UvmBundleTesterBase
import jnr.ffi.LibraryLoader
import PlatformConstants._
import NativeSupport._
import org.scalatest.FlatSpec
import org.scalatest.Matchers
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
val ncs_tests = LibraryLoader.create(classOf[NcsTestsLib]).load(fileName)
class NativeClientSupportTest extends FlatSpec with Matchers {
"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))
mvm shouldBe microVM
\ No newline at end of file
MU_INCLUDE = ../../cinclude
.PHONY: all
all: structtest.c
cc -fPIC -shared -o structtest.c callbacktest.c
cc -fPIC -shared -o callbacktest.c ncs_tests.c
cc -fPIC -shared -I $(MU_INCLUDE) -o ncs_tests.c
#include <stdio.h>
#include <muapi.h>
void test_basic(MuVM *mvm) {
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);
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment