diff --git a/meta/classes-recipe/ptest.bbclass b/meta/classes-recipe/ptest.bbclass
index 0f80fbc1d8..1721d215e7 100644
--- a/meta/classes-recipe/ptest.bbclass
+++ b/meta/classes-recipe/ptest.bbclass
@@ -118,6 +118,47 @@ python ptest_update_alternatives() {
                 os.symlink(alt_target, os.path.join(ptest_bindir, alt_name))
 }
 
+# PTEST_SKIP varflags name tests relative to PTEST_SKIP_DIR, with the
+# skip reason as value. Empty values mean no skip.
+#
+# Skipped tests are replaced with scripts exiting 77. Missing tests
+# are fatal. Supports skipping a directory also 
+PTEST_SKIP_DIR ?= "${PTEST_PATH}"
+
+PACKAGE_PREPROCESS_FUNCS:append = "${@bb.utils.contains('PTEST_ENABLED', '1', ' ptest_apply_skips', '', d)}"
+
+def ptest_skip_if(override, reason, d):
+    return reason if override in d.getVar('OVERRIDES').split(':') else ''
+
+def ptest_skip_entries(d):
+    flags = d.getVarFlags('PTEST_SKIP') or {}
+    return [(t, d.getVarFlag('PTEST_SKIP', t)) for t in sorted(flags) if d.getVarFlag('PTEST_SKIP', t)]
+
+# Entries are dynamic varflags, so hash them via PTEST_SKIP_SIGNATURE (set below)
+ptest_apply_skips[vardeps] += "PTEST_SKIP_SIGNATURE PTEST_SKIP_DIR"
+
+python ptest_apply_skips() {
+    import shlex
+    skip_dir = d.getVar('PKGD') + d.getVar('PTEST_SKIP_DIR')
+    for test, reason in ptest_skip_entries(d):
+        path = os.path.join(skip_dir, test)
+        if os.path.isdir(path):
+            files = [os.path.join(root, f) for root, _, names in os.walk(path) for f in names
+                     if not os.path.islink(os.path.join(root, f))]
+            if not files:
+                bb.fatal("PTEST_SKIP: directory %s contains no files" % test)
+            bb.note("PTEST_SKIP: %s is a directory, skipping all %d files in it" % (test, len(files)))
+        elif os.path.isfile(path):
+            files = [path]
+        else:
+            bb.fatal("PTEST_SKIP: %s not found in %s" % (test, d.getVar('PTEST_SKIP_DIR')))
+        for file in files:
+            name = os.path.relpath(file, skip_dir)
+            with open(file, 'w') as f:
+                f.write('#!/bin/sh\necho %s >&2\nexit 77\n' % shlex.quote("SKIP %s: %s" % (name, reason)))
+            bb.note("PTEST_SKIP: skipping %s (%s)" % (name, reason))
+}
+
 do_configure_ptest_base[dirs] = "${B}"
 do_compile_ptest_base[dirs] = "${B}"
 do_install_ptest_base[dirs] = "${B}"
@@ -136,6 +177,8 @@ python () {
     if not(d.getVar('PTEST_ENABLED') == "1"):
         for i in ['do_configure_ptest_base', 'do_compile_ptest_base', 'do_install_ptest_base']:
             bb.build.deltask(i, d)
+
+    d.setVar('PTEST_SKIP_SIGNATURE', ' '.join('%s=%s' % e for e in ptest_skip_entries(d)))
 }
 
 QARECIPETEST[missing-ptest] = "package_qa_check_missing_ptest"
