|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +package org.pytorch.executorch; |
| 10 | + |
| 11 | +import static org.junit.Assert.assertEquals; |
| 12 | +import static org.junit.Assert.assertTrue; |
| 13 | +import static org.junit.Assert.assertFalse; |
| 14 | +import static org.junit.Assert.assertNotEquals; |
| 15 | +import static org.junit.Assert.fail; |
| 16 | + |
| 17 | +import android.os.Environment; |
| 18 | +import androidx.test.rule.GrantPermissionRule; |
| 19 | +import android.Manifest; |
| 20 | +import android.content.Context; |
| 21 | +import org.junit.Test; |
| 22 | +import org.junit.Before; |
| 23 | +import org.junit.Rule; |
| 24 | +import org.junit.runner.RunWith; |
| 25 | +import java.io.InputStream; |
| 26 | +import java.net.URI; |
| 27 | +import java.net.URISyntaxException; |
| 28 | +import java.util.concurrent.CountDownLatch; |
| 29 | +import java.util.concurrent.atomic.AtomicInteger; |
| 30 | +import java.io.IOException; |
| 31 | +import java.io.File; |
| 32 | +import java.io.FileOutputStream; |
| 33 | +import org.junit.runners.JUnit4; |
| 34 | +import org.apache.commons.io.FileUtils; |
| 35 | +import androidx.test.ext.junit.runners.AndroidJUnit4; |
| 36 | +import androidx.test.InstrumentationRegistry; |
| 37 | + |
| 38 | +/** Unit tests for {@link Module}. */ |
| 39 | +@RunWith(AndroidJUnit4.class) |
| 40 | +public class ModuleE2ETest { |
| 41 | + private static String getTestFilePath(String fileName) { |
| 42 | + return InstrumentationRegistry.getInstrumentation().getTargetContext().getExternalCacheDir() + fileName; |
| 43 | + } |
| 44 | + |
| 45 | + @Rule |
| 46 | + public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.READ_EXTERNAL_STORAGE); |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testMv2Fp32() throws IOException, URISyntaxException{ |
| 50 | + String filePath = "/mv2_xnnpack_fp32.pte"; |
| 51 | + File pteFile = new File(getTestFilePath(filePath)); |
| 52 | + InputStream inputStream = getClass().getResourceAsStream(filePath); |
| 53 | + FileUtils.copyInputStreamToFile(inputStream, pteFile); |
| 54 | + inputStream.close(); |
| 55 | + |
| 56 | + Module module = Module.load(getTestFilePath(filePath)); |
| 57 | + |
| 58 | + EValue[] results = module.forward(); |
| 59 | + assertTrue(results[0].isTensor()); |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments