-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,463 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This folder includes test data, scripts and source code that used to test the export functionality of onnxruntime-web package. |
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,40 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
/** | ||
* Entry point for package exports tests. | ||
* | ||
* @param {string[]} packagesToInstall | ||
*/ | ||
module.exports = async function main() { | ||
console.log('Running exports tests...'); | ||
|
||
// testcases/nextjs-default | ||
{ | ||
const workingDir = path.join(__dirname, 'testcases/nextjs-default'); | ||
await runShellCmd('npm install ../../onnxruntime-common.tgz ../../onnxruntime-web.tgz', workingDir); | ||
} | ||
}; | ||
|
||
async function runShellCmd(cmd, wd = __dirname) { | ||
console.log('==============================================================='); | ||
console.log(' Running command in shell:'); | ||
console.log(' > ' + cmd); | ||
console.log('==============================================================='); | ||
let complete = false; | ||
const childProcess = spawn(cmd, { shell: true, stdio: 'inherit', cwd: wd }); | ||
childProcess.on('close', function (code) { | ||
if (code !== 0) { | ||
process.exit(code); | ||
} else { | ||
complete = true; | ||
} | ||
}); | ||
while (!complete) { | ||
await delay(100); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
js/web/test/e2e/exports/testcases/nextjs-default/.gitignore
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,40 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.* | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/versions | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# env files (can opt-in for committing if needed) | ||
.env* | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
36 changes: 36 additions & 0 deletions
36
js/web/test/e2e/exports/testcases/nextjs-default/README.md
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,36 @@ | ||
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). | ||
|
||
## Getting Started | ||
|
||
First, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
# or | ||
pnpm dev | ||
# or | ||
bun dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `app/page.js`. The page auto-updates as you edit the file. | ||
|
||
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. |
Binary file not shown.
Binary file added
BIN
+66.3 KB
js/web/test/e2e/exports/testcases/nextjs-default/app/fonts/GeistMonoVF.woff
Binary file not shown.
Binary file added
BIN
+64.7 KB
js/web/test/e2e/exports/testcases/nextjs-default/app/fonts/GeistVF.woff
Binary file not shown.
42 changes: 42 additions & 0 deletions
42
js/web/test/e2e/exports/testcases/nextjs-default/app/globals.css
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,42 @@ | ||
:root { | ||
--background: #ffffff; | ||
--foreground: #171717; | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
:root { | ||
--background: #0a0a0a; | ||
--foreground: #ededed; | ||
} | ||
} | ||
|
||
html, | ||
body { | ||
max-width: 100vw; | ||
overflow-x: hidden; | ||
} | ||
|
||
body { | ||
color: var(--foreground); | ||
background: var(--background); | ||
font-family: Arial, Helvetica, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
* { | ||
box-sizing: border-box; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
a { | ||
color: inherit; | ||
text-decoration: none; | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
html { | ||
color-scheme: dark; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
js/web/test/e2e/exports/testcases/nextjs-default/app/layout.js
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,28 @@ | ||
import localFont from "next/font/local"; | ||
import "./globals.css"; | ||
|
||
const geistSans = localFont({ | ||
src: "./fonts/GeistVF.woff", | ||
variable: "--font-geist-sans", | ||
weight: "100 900", | ||
}); | ||
const geistMono = localFont({ | ||
src: "./fonts/GeistMonoVF.woff", | ||
variable: "--font-geist-mono", | ||
weight: "100 900", | ||
}); | ||
|
||
export const metadata = { | ||
title: "Create Next App", | ||
description: "Generated by create next app", | ||
}; | ||
|
||
export default function RootLayout({ children }) { | ||
return ( | ||
<html lang="en"> | ||
<body className={`${geistSans.variable} ${geistMono.variable}`}> | ||
{children} | ||
</body> | ||
</html> | ||
); | ||
} |
58 changes: 58 additions & 0 deletions
58
js/web/test/e2e/exports/testcases/nextjs-default/app/onnx-helper.js
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,58 @@ | ||
import * as ort from 'onnxruntime-web'; | ||
|
||
// Model data for "test_abs/model.onnx" | ||
const testModelData = | ||
'CAcSDGJhY2tlbmQtdGVzdDpJCgsKAXgSAXkiA0FicxIIdGVzdF9hYnNaFwoBeBISChAIARIMCgIIAwoCCAQKAggFYhcKAXkSEgoQCAESDAoCCAMKAggECgIIBUIECgAQDQ=='; | ||
|
||
const base64StringToUint8Array = (base64String) => { | ||
const charArray = atob(base64String); | ||
const length = charArray.length; | ||
const buffer = new Uint8Array(new ArrayBuffer(length)); | ||
for (let i = 0; i < length; i++) { | ||
buffer[i] = charArray.charCodeAt(i); | ||
} | ||
return buffer; | ||
}; | ||
|
||
let mySession; | ||
|
||
const assert = (cond, msg) => { | ||
if (!cond) throw new Error(msg); | ||
}; | ||
|
||
export const createTestSession = async (multiThreaded, proxy) => { | ||
const model = base64StringToUint8Array(testModelData); | ||
const options = {}; | ||
|
||
if (multiThreaded) { | ||
ort.env.wasm.numThreads = 2; | ||
assert(typeof SharedArrayBuffer !== 'undefined', 'SharedArrayBuffer is not supported'); | ||
} | ||
if (proxy) { | ||
ort.env.wasm.proxy = true; | ||
} | ||
mySession = await ort.InferenceSession.create(model, options); | ||
}; | ||
|
||
export const runTestSessionAndValidate = async () => { | ||
try { | ||
// test data: [0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, ... 58, -59] | ||
const inputData = [...Array(60).keys()].map((i) => (i % 2 === 0 ? i : -i)); | ||
const expectedOutputData = inputData.map((i) => Math.abs(i)); | ||
|
||
const fetches = await mySession.run({ x: new ort.Tensor('float32', inputData, [3, 4, 5]) }); | ||
|
||
const y = fetches.y; | ||
|
||
assert(y instanceof ort.Tensor, 'unexpected result'); | ||
assert(y.dims.length === 3 && y.dims[0] === 3 && y.dims[1] === 4 && y.dims[2] === 5, 'incorrect shape'); | ||
|
||
for (let i = 0; i < expectedOutputData.length; i++) { | ||
assert(y.data[i] === expectedOutputData[i], `output data mismatch at index ${i}`); | ||
} | ||
|
||
return 'PASS'; | ||
} catch (e) { | ||
return `FAIL: ${e}`; | ||
} | ||
}; |
95 changes: 95 additions & 0 deletions
95
js/web/test/e2e/exports/testcases/nextjs-default/app/page.js
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,95 @@ | ||
'use client'; | ||
|
||
import Image from "next/image"; | ||
import styles from "./page.module.css"; | ||
import dynamic from 'next/dynamic'; | ||
|
||
const OnnxTestBarComponent = dynamic(() => import('../components/onnx-test-bar'), { ssr: false }); | ||
|
||
export default function Home() { | ||
return ( | ||
<div className={styles.page}> | ||
<main className={styles.main}> | ||
<Image | ||
className={styles.logo} | ||
src="/next.svg" | ||
alt="Next.js logo" | ||
width={180} | ||
height={38} | ||
priority | ||
/> | ||
<OnnxTestBarComponent /> | ||
|
||
<div className={styles.ctas}> | ||
<a | ||
className={styles.primary} | ||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
<Image | ||
className={styles.logo} | ||
src="/vercel.svg" | ||
alt="Vercel logomark" | ||
width={20} | ||
height={20} | ||
/> | ||
Deploy now | ||
</a> | ||
<a | ||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className={styles.secondary} | ||
> | ||
Read our docs | ||
</a> | ||
</div> | ||
</main> | ||
<footer className={styles.footer}> | ||
<a | ||
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
<Image | ||
aria-hidden | ||
src="/file.svg" | ||
alt="File icon" | ||
width={16} | ||
height={16} | ||
/> | ||
Learn | ||
</a> | ||
<a | ||
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
<Image | ||
aria-hidden | ||
src="/window.svg" | ||
alt="Window icon" | ||
width={16} | ||
height={16} | ||
/> | ||
Examples | ||
</a> | ||
<a | ||
href="https://nextjs.org?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
<Image | ||
aria-hidden | ||
src="/globe.svg" | ||
alt="Globe icon" | ||
width={16} | ||
height={16} | ||
/> | ||
Go to nextjs.org → | ||
</a> | ||
</footer> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.